{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "frank-jefferson",
   "metadata": {},
   "source": [
    "## pandas数据结构"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "adopted-optics",
   "metadata": {},
   "source": [
    "### Series"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "paperback-module",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd  #pandas 基于numppy，升级"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "third-capital",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A    1\n",
       "B    2\n",
       "C    3\n",
       "D    4\n",
       "E    5\n",
       "dtype: int64"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s1 = pd.Series(data=[1,2,3,4,5],index=list('ABCDE'))\n",
    "s1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "turned-leadership",
   "metadata": {},
   "source": [
    "### DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "residential-danger",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>83.0</td>\n",
       "      <td>149.0</td>\n",
       "      <td>37.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>67.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>132.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>75.0</td>\n",
       "      <td>127.0</td>\n",
       "      <td>110.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>36.0</td>\n",
       "      <td>51.0</td>\n",
       "      <td>59.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>37.0</td>\n",
       "      <td>135.0</td>\n",
       "      <td>59.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>147.0</td>\n",
       "      <td>131.0</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>140.0</td>\n",
       "      <td>13.0</td>\n",
       "      <td>98.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>36.0</td>\n",
       "      <td>56.0</td>\n",
       "      <td>146.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>138.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>139.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>120.0</td>\n",
       "      <td>62.0</td>\n",
       "      <td>117.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   python   math  english\n",
       "A    83.0  149.0     37.0\n",
       "B    67.0   10.0    132.0\n",
       "C    75.0  127.0    110.0\n",
       "D    36.0   51.0     59.0\n",
       "E    37.0  135.0     59.0\n",
       "F   147.0  131.0      3.0\n",
       "G   140.0   13.0     98.0\n",
       "H    36.0   56.0    146.0\n",
       "I   138.0   80.0    139.0\n",
       "J   120.0   62.0    117.0"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1 = pd.DataFrame(data = np.random.randint(0,151,size =(10,3)),\n",
    "                   index=list('ABCDEFGHIJ'),\n",
    "                   columns=['python','math','english'],\n",
    "                   dtype=np.float16)\n",
    "df1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "pointed-glasgow",
   "metadata": {},
   "source": [
    "## 数据查看"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "unusual-diamond",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>68.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>11.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>41.0</td>\n",
       "      <td>107.0</td>\n",
       "      <td>109.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>141.0</td>\n",
       "      <td>105.0</td>\n",
       "      <td>107.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>54.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>82.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>31.0</td>\n",
       "      <td>103.0</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>48.0</td>\n",
       "      <td>85.0</td>\n",
       "      <td>89.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>140.0</td>\n",
       "      <td>115.0</td>\n",
       "      <td>55.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>43.0</td>\n",
       "      <td>102.0</td>\n",
       "      <td>96.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>22.0</td>\n",
       "      <td>53.0</td>\n",
       "      <td>116.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>146.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>120.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>28.0</td>\n",
       "      <td>61.0</td>\n",
       "      <td>100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>68.0</td>\n",
       "      <td>61.0</td>\n",
       "      <td>85.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>31.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>110.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>87.0</td>\n",
       "      <td>67.0</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>34.0</td>\n",
       "      <td>41.0</td>\n",
       "      <td>135.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>42.0</td>\n",
       "      <td>105.0</td>\n",
       "      <td>126.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>113.0</td>\n",
       "      <td>91.0</td>\n",
       "      <td>136.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>52.0</td>\n",
       "      <td>139.0</td>\n",
       "      <td>29.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>88.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>48.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>44.0</td>\n",
       "      <td>55.0</td>\n",
       "      <td>12.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>22.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>21.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>135.0</td>\n",
       "      <td>125.0</td>\n",
       "      <td>61.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>97.0</td>\n",
       "      <td>60.0</td>\n",
       "      <td>15.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>144.0</td>\n",
       "      <td>143.0</td>\n",
       "      <td>125.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>144.0</td>\n",
       "      <td>45.0</td>\n",
       "      <td>52.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>78.0</td>\n",
       "      <td>86.0</td>\n",
       "      <td>127.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>133.0</td>\n",
       "      <td>138.0</td>\n",
       "      <td>29.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>39.0</td>\n",
       "      <td>70.0</td>\n",
       "      <td>69.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>142.0</td>\n",
       "      <td>105.0</td>\n",
       "      <td>84.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>127.0</td>\n",
       "      <td>14.0</td>\n",
       "      <td>91.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>95.0</td>\n",
       "      <td>65.0</td>\n",
       "      <td>88.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>74.0</td>\n",
       "      <td>56.0</td>\n",
       "      <td>59.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>122.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>65.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>115.0</td>\n",
       "      <td>128.0</td>\n",
       "      <td>138.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>74</th>\n",
       "      <td>58.0</td>\n",
       "      <td>122.0</td>\n",
       "      <td>150.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <td>133.0</td>\n",
       "      <td>102.0</td>\n",
       "      <td>104.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>80.0</td>\n",
       "      <td>115.0</td>\n",
       "      <td>77.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>126.0</td>\n",
       "      <td>49.0</td>\n",
       "      <td>103.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>113.0</td>\n",
       "      <td>26.0</td>\n",
       "      <td>45.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>10.0</td>\n",
       "      <td>47.0</td>\n",
       "      <td>138.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>45.0</td>\n",
       "      <td>106.0</td>\n",
       "      <td>79.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>149.0</td>\n",
       "      <td>97.0</td>\n",
       "      <td>143.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>27.0</td>\n",
       "      <td>66.0</td>\n",
       "      <td>40.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>11.0</td>\n",
       "      <td>73.0</td>\n",
       "      <td>84.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>77.0</td>\n",
       "      <td>112.0</td>\n",
       "      <td>16.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>85</th>\n",
       "      <td>105.0</td>\n",
       "      <td>137.0</td>\n",
       "      <td>11.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>86</th>\n",
       "      <td>115.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>113.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>113.0</td>\n",
       "      <td>70.0</td>\n",
       "      <td>54.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>135.0</td>\n",
       "      <td>49.0</td>\n",
       "      <td>73.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89</th>\n",
       "      <td>2.0</td>\n",
       "      <td>128.0</td>\n",
       "      <td>11.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>90</th>\n",
       "      <td>137.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>59.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>91</th>\n",
       "      <td>55.0</td>\n",
       "      <td>108.0</td>\n",
       "      <td>55.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92</th>\n",
       "      <td>108.0</td>\n",
       "      <td>56.0</td>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93</th>\n",
       "      <td>129.0</td>\n",
       "      <td>93.0</td>\n",
       "      <td>36.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>94</th>\n",
       "      <td>50.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>7.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>95.0</td>\n",
       "      <td>112.0</td>\n",
       "      <td>116.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>38.0</td>\n",
       "      <td>34.0</td>\n",
       "      <td>120.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>23.0</td>\n",
       "      <td>66.0</td>\n",
       "      <td>61.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>45.0</td>\n",
       "      <td>49.0</td>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>2.0</td>\n",
       "      <td>27.0</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    python   math  english\n",
       "0     68.0    5.0     11.0\n",
       "1     41.0  107.0    109.0\n",
       "2    141.0  105.0    107.0\n",
       "3     54.0   21.0     82.0\n",
       "4     31.0  103.0      3.0\n",
       "5     48.0   85.0     89.0\n",
       "6    140.0  115.0     55.0\n",
       "7     43.0  102.0     96.0\n",
       "8     22.0   53.0    116.0\n",
       "9    146.0   90.0    120.0\n",
       "10    28.0   61.0    100.0\n",
       "11    68.0   61.0     85.0\n",
       "12    31.0    0.0    110.0\n",
       "13    87.0   67.0     20.0\n",
       "14    34.0   41.0    135.0\n",
       "15    42.0  105.0    126.0\n",
       "16   113.0   91.0    136.0\n",
       "17    52.0  139.0     29.0\n",
       "18    88.0    4.0     48.0\n",
       "19    44.0   55.0     12.0\n",
       "20    22.0   21.0     21.0\n",
       "21   135.0  125.0     61.0\n",
       "22    97.0   60.0     15.0\n",
       "23   144.0  143.0    125.0\n",
       "24   144.0   45.0     52.0\n",
       "25    78.0   86.0    127.0\n",
       "26   133.0  138.0     29.0\n",
       "27    39.0   70.0     69.0\n",
       "28   142.0  105.0     84.0\n",
       "29   127.0   14.0     91.0\n",
       "..     ...    ...      ...\n",
       "70    95.0   65.0     88.0\n",
       "71    74.0   56.0     59.0\n",
       "72   122.0    2.0     65.0\n",
       "73   115.0  128.0    138.0\n",
       "74    58.0  122.0    150.0\n",
       "75   133.0  102.0    104.0\n",
       "76    80.0  115.0     77.0\n",
       "77   126.0   49.0    103.0\n",
       "78   113.0   26.0     45.0\n",
       "79    10.0   47.0    138.0\n",
       "80    45.0  106.0     79.0\n",
       "81   149.0   97.0    143.0\n",
       "82    27.0   66.0     40.0\n",
       "83    11.0   73.0     84.0\n",
       "84    77.0  112.0     16.0\n",
       "85   105.0  137.0     11.0\n",
       "86   115.0   90.0    113.0\n",
       "87   113.0   70.0     54.0\n",
       "88   135.0   49.0     73.0\n",
       "89     2.0  128.0     11.0\n",
       "90   137.0   15.0     59.0\n",
       "91    55.0  108.0     55.0\n",
       "92   108.0   56.0     50.0\n",
       "93   129.0   93.0     36.0\n",
       "94    50.0   50.0      7.0\n",
       "95    95.0  112.0    116.0\n",
       "96    38.0   34.0    120.0\n",
       "97    23.0   66.0     61.0\n",
       "98    45.0   49.0     50.0\n",
       "99     2.0   27.0     20.0\n",
       "\n",
       "[100 rows x 3 columns]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,151,size =(100,3)),\n",
    "                   columns=['python','math','english'],\n",
    "                   dtype=np.float16)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "aerial-sight",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(100, 3)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "intense-veteran",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>68.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>11.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>41.0</td>\n",
       "      <td>107.0</td>\n",
       "      <td>109.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>141.0</td>\n",
       "      <td>105.0</td>\n",
       "      <td>107.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>54.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>82.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>31.0</td>\n",
       "      <td>103.0</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   python   math  english\n",
       "0    68.0    5.0     11.0\n",
       "1    41.0  107.0    109.0\n",
       "2   141.0  105.0    107.0\n",
       "3    54.0   21.0     82.0\n",
       "4    31.0  103.0      3.0"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head() #显示前n个"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "enhanced-mexico",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>23.0</td>\n",
       "      <td>66.0</td>\n",
       "      <td>61.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>45.0</td>\n",
       "      <td>49.0</td>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>2.0</td>\n",
       "      <td>27.0</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    python  math  english\n",
       "97    23.0  66.0     61.0\n",
       "98    45.0  49.0     50.0\n",
       "99     2.0  27.0     20.0"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.tail(3) #显示后3个"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "removed-findings",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "python     float16\n",
       "math       float16\n",
       "english    float16\n",
       "dtype: object"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "dominant-excellence",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 100 entries, 0 to 99\n",
      "Data columns (total 3 columns):\n",
      "python     100 non-null float16\n",
      "math       100 non-null float16\n",
      "english    100 non-null float16\n",
      "dtypes: float16(3)\n",
      "memory usage: 680.0 bytes\n"
     ]
    }
   ],
   "source": [
    "df.info() #比较详细的信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "cutting-appreciation",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>100.0000</td>\n",
       "      <td>100.00000</td>\n",
       "      <td>100.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>79.7500</td>\n",
       "      <td>77.06250</td>\n",
       "      <td>70.0625</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>43.8125</td>\n",
       "      <td>41.21875</td>\n",
       "      <td>39.4375</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>2.0000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>3.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>42.7500</td>\n",
       "      <td>45.75000</td>\n",
       "      <td>43.7500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>80.5000</td>\n",
       "      <td>81.50000</td>\n",
       "      <td>61.5000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>115.2500</td>\n",
       "      <td>107.25000</td>\n",
       "      <td>103.2500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>149.0000</td>\n",
       "      <td>149.00000</td>\n",
       "      <td>150.0000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         python       math   english\n",
       "count  100.0000  100.00000  100.0000\n",
       "mean    79.7500   77.06250   70.0625\n",
       "std     43.8125   41.21875   39.4375\n",
       "min      2.0000    0.00000    3.0000\n",
       "25%     42.7500   45.75000   43.7500\n",
       "50%     80.5000   81.50000   61.5000\n",
       "75%    115.2500  107.25000  103.2500\n",
       "max    149.0000  149.00000  150.0000"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.describe() #平均值，标准差，中位数，四等分，最大最小值，"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "occupied-improvement",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 68.,   5.,  11.],\n",
       "       [ 41., 107., 109.],\n",
       "       [141., 105., 107.],\n",
       "       [ 54.,  21.,  82.],\n",
       "       [ 31., 103.,   3.],\n",
       "       [ 48.,  85.,  89.],\n",
       "       [140., 115.,  55.],\n",
       "       [ 43., 102.,  96.],\n",
       "       [ 22.,  53., 116.],\n",
       "       [146.,  90., 120.],\n",
       "       [ 28.,  61., 100.],\n",
       "       [ 68.,  61.,  85.],\n",
       "       [ 31.,   0., 110.],\n",
       "       [ 87.,  67.,  20.],\n",
       "       [ 34.,  41., 135.],\n",
       "       [ 42., 105., 126.],\n",
       "       [113.,  91., 136.],\n",
       "       [ 52., 139.,  29.],\n",
       "       [ 88.,   4.,  48.],\n",
       "       [ 44.,  55.,  12.],\n",
       "       [ 22.,  21.,  21.],\n",
       "       [135., 125.,  61.],\n",
       "       [ 97.,  60.,  15.],\n",
       "       [144., 143., 125.],\n",
       "       [144.,  45.,  52.],\n",
       "       [ 78.,  86., 127.],\n",
       "       [133., 138.,  29.],\n",
       "       [ 39.,  70.,  69.],\n",
       "       [142., 105.,  84.],\n",
       "       [127.,  14.,  91.],\n",
       "       [116.,  92., 111.],\n",
       "       [147.,  46.,  85.],\n",
       "       [ 95.,  38., 138.],\n",
       "       [ 12.,  25.,  45.],\n",
       "       [112., 149.,  92.],\n",
       "       [ 55.,  92., 131.],\n",
       "       [ 74.,  10.,  80.],\n",
       "       [  8.,  33.,  51.],\n",
       "       [ 78.,  59.,  45.],\n",
       "       [110., 104., 133.],\n",
       "       [108., 118.,  54.],\n",
       "       [ 52.,  93.,  25.],\n",
       "       [ 58.,  37.,  36.],\n",
       "       [ 74., 101.,  46.],\n",
       "       [123., 115.,  62.],\n",
       "       [ 21.,  99.,  78.],\n",
       "       [106., 134.,  21.],\n",
       "       [ 70., 148.,  58.],\n",
       "       [101.,  18.,  63.],\n",
       "       [ 95., 104.,  47.],\n",
       "       [ 29., 139.,  61.],\n",
       "       [ 84., 136.,  69.],\n",
       "       [ 90., 128.,  57.],\n",
       "       [ 65., 145.,   9.],\n",
       "       [ 23.,  82.,  32.],\n",
       "       [ 41.,  82.,  50.],\n",
       "       [ 81.,  75.,  50.],\n",
       "       [126.,  67.,  57.],\n",
       "       [146.,  56.,  71.],\n",
       "       [ 83., 142.,  36.],\n",
       "       [114., 110., 120.],\n",
       "       [ 23.,  13., 134.],\n",
       "       [130.,  43.,  64.],\n",
       "       [108., 133.,  38.],\n",
       "       [146.,  43., 126.],\n",
       "       [117.,  17.,  45.],\n",
       "       [ 54.,  10.,  29.],\n",
       "       [  4.,  35.,  16.],\n",
       "       [  2.,  88.,  28.],\n",
       "       [126.,  81.,  87.],\n",
       "       [ 95.,  65.,  88.],\n",
       "       [ 74.,  56.,  59.],\n",
       "       [122.,   2.,  65.],\n",
       "       [115., 128., 138.],\n",
       "       [ 58., 122., 150.],\n",
       "       [133., 102., 104.],\n",
       "       [ 80., 115.,  77.],\n",
       "       [126.,  49., 103.],\n",
       "       [113.,  26.,  45.],\n",
       "       [ 10.,  47., 138.],\n",
       "       [ 45., 106.,  79.],\n",
       "       [149.,  97., 143.],\n",
       "       [ 27.,  66.,  40.],\n",
       "       [ 11.,  73.,  84.],\n",
       "       [ 77., 112.,  16.],\n",
       "       [105., 137.,  11.],\n",
       "       [115.,  90., 113.],\n",
       "       [113.,  70.,  54.],\n",
       "       [135.,  49.,  73.],\n",
       "       [  2., 128.,  11.],\n",
       "       [137.,  15.,  59.],\n",
       "       [ 55., 108.,  55.],\n",
       "       [108.,  56.,  50.],\n",
       "       [129.,  93.,  36.],\n",
       "       [ 50.,  50.,   7.],\n",
       "       [ 95., 112., 116.],\n",
       "       [ 38.,  34., 120.],\n",
       "       [ 23.,  66.,  61.],\n",
       "       [ 45.,  49.,  50.],\n",
       "       [  2.,  27.,  20.]], dtype=float16)"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.values  #值，返回的是numpy数组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "governing-exception",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['python', 'math', 'english'], dtype='object')"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns #列索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "standard-gallery",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RangeIndex(start=0, stop=100, step=1)"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.index #行索引"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "grateful-recipient",
   "metadata": {},
   "source": [
    "## 数据输入与输出"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "modular-reform",
   "metadata": {},
   "source": [
    "### csv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "educated-messenger",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.to_csv('./data.csv',sep=',',\n",
    "          index=False, #保存行索引\n",
    "          header=True #保存列索引\n",
    "         ) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "rocky-colonial",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>68.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>11.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>41.0</td>\n",
       "      <td>107.0</td>\n",
       "      <td>109.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>141.0</td>\n",
       "      <td>105.0</td>\n",
       "      <td>107.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>54.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>82.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>31.0</td>\n",
       "      <td>103.0</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>48.0</td>\n",
       "      <td>85.0</td>\n",
       "      <td>89.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>140.0</td>\n",
       "      <td>115.0</td>\n",
       "      <td>55.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>43.0</td>\n",
       "      <td>102.0</td>\n",
       "      <td>96.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>22.0</td>\n",
       "      <td>53.0</td>\n",
       "      <td>116.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>146.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>120.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>28.0</td>\n",
       "      <td>61.0</td>\n",
       "      <td>100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>68.0</td>\n",
       "      <td>61.0</td>\n",
       "      <td>85.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>31.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>110.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>87.0</td>\n",
       "      <td>67.0</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>34.0</td>\n",
       "      <td>41.0</td>\n",
       "      <td>135.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>42.0</td>\n",
       "      <td>105.0</td>\n",
       "      <td>126.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>113.0</td>\n",
       "      <td>91.0</td>\n",
       "      <td>136.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>52.0</td>\n",
       "      <td>139.0</td>\n",
       "      <td>29.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>88.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>48.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>44.0</td>\n",
       "      <td>55.0</td>\n",
       "      <td>12.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>22.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>21.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>135.0</td>\n",
       "      <td>125.0</td>\n",
       "      <td>61.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>97.0</td>\n",
       "      <td>60.0</td>\n",
       "      <td>15.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>144.0</td>\n",
       "      <td>143.0</td>\n",
       "      <td>125.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>144.0</td>\n",
       "      <td>45.0</td>\n",
       "      <td>52.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>78.0</td>\n",
       "      <td>86.0</td>\n",
       "      <td>127.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>133.0</td>\n",
       "      <td>138.0</td>\n",
       "      <td>29.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>39.0</td>\n",
       "      <td>70.0</td>\n",
       "      <td>69.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>142.0</td>\n",
       "      <td>105.0</td>\n",
       "      <td>84.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>127.0</td>\n",
       "      <td>14.0</td>\n",
       "      <td>91.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>95.0</td>\n",
       "      <td>65.0</td>\n",
       "      <td>88.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>74.0</td>\n",
       "      <td>56.0</td>\n",
       "      <td>59.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>122.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>65.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>115.0</td>\n",
       "      <td>128.0</td>\n",
       "      <td>138.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>74</th>\n",
       "      <td>58.0</td>\n",
       "      <td>122.0</td>\n",
       "      <td>150.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <td>133.0</td>\n",
       "      <td>102.0</td>\n",
       "      <td>104.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>80.0</td>\n",
       "      <td>115.0</td>\n",
       "      <td>77.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>126.0</td>\n",
       "      <td>49.0</td>\n",
       "      <td>103.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>113.0</td>\n",
       "      <td>26.0</td>\n",
       "      <td>45.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>10.0</td>\n",
       "      <td>47.0</td>\n",
       "      <td>138.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>45.0</td>\n",
       "      <td>106.0</td>\n",
       "      <td>79.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>149.0</td>\n",
       "      <td>97.0</td>\n",
       "      <td>143.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>27.0</td>\n",
       "      <td>66.0</td>\n",
       "      <td>40.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>11.0</td>\n",
       "      <td>73.0</td>\n",
       "      <td>84.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>77.0</td>\n",
       "      <td>112.0</td>\n",
       "      <td>16.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>85</th>\n",
       "      <td>105.0</td>\n",
       "      <td>137.0</td>\n",
       "      <td>11.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>86</th>\n",
       "      <td>115.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>113.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>113.0</td>\n",
       "      <td>70.0</td>\n",
       "      <td>54.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>135.0</td>\n",
       "      <td>49.0</td>\n",
       "      <td>73.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89</th>\n",
       "      <td>2.0</td>\n",
       "      <td>128.0</td>\n",
       "      <td>11.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>90</th>\n",
       "      <td>137.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>59.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>91</th>\n",
       "      <td>55.0</td>\n",
       "      <td>108.0</td>\n",
       "      <td>55.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92</th>\n",
       "      <td>108.0</td>\n",
       "      <td>56.0</td>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93</th>\n",
       "      <td>129.0</td>\n",
       "      <td>93.0</td>\n",
       "      <td>36.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>94</th>\n",
       "      <td>50.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>7.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>95.0</td>\n",
       "      <td>112.0</td>\n",
       "      <td>116.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>38.0</td>\n",
       "      <td>34.0</td>\n",
       "      <td>120.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>23.0</td>\n",
       "      <td>66.0</td>\n",
       "      <td>61.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>45.0</td>\n",
       "      <td>49.0</td>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>2.0</td>\n",
       "      <td>27.0</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    python   math  english\n",
       "0     68.0    5.0     11.0\n",
       "1     41.0  107.0    109.0\n",
       "2    141.0  105.0    107.0\n",
       "3     54.0   21.0     82.0\n",
       "4     31.0  103.0      3.0\n",
       "5     48.0   85.0     89.0\n",
       "6    140.0  115.0     55.0\n",
       "7     43.0  102.0     96.0\n",
       "8     22.0   53.0    116.0\n",
       "9    146.0   90.0    120.0\n",
       "10    28.0   61.0    100.0\n",
       "11    68.0   61.0     85.0\n",
       "12    31.0    0.0    110.0\n",
       "13    87.0   67.0     20.0\n",
       "14    34.0   41.0    135.0\n",
       "15    42.0  105.0    126.0\n",
       "16   113.0   91.0    136.0\n",
       "17    52.0  139.0     29.0\n",
       "18    88.0    4.0     48.0\n",
       "19    44.0   55.0     12.0\n",
       "20    22.0   21.0     21.0\n",
       "21   135.0  125.0     61.0\n",
       "22    97.0   60.0     15.0\n",
       "23   144.0  143.0    125.0\n",
       "24   144.0   45.0     52.0\n",
       "25    78.0   86.0    127.0\n",
       "26   133.0  138.0     29.0\n",
       "27    39.0   70.0     69.0\n",
       "28   142.0  105.0     84.0\n",
       "29   127.0   14.0     91.0\n",
       "..     ...    ...      ...\n",
       "70    95.0   65.0     88.0\n",
       "71    74.0   56.0     59.0\n",
       "72   122.0    2.0     65.0\n",
       "73   115.0  128.0    138.0\n",
       "74    58.0  122.0    150.0\n",
       "75   133.0  102.0    104.0\n",
       "76    80.0  115.0     77.0\n",
       "77   126.0   49.0    103.0\n",
       "78   113.0   26.0     45.0\n",
       "79    10.0   47.0    138.0\n",
       "80    45.0  106.0     79.0\n",
       "81   149.0   97.0    143.0\n",
       "82    27.0   66.0     40.0\n",
       "83    11.0   73.0     84.0\n",
       "84    77.0  112.0     16.0\n",
       "85   105.0  137.0     11.0\n",
       "86   115.0   90.0    113.0\n",
       "87   113.0   70.0     54.0\n",
       "88   135.0   49.0     73.0\n",
       "89     2.0  128.0     11.0\n",
       "90   137.0   15.0     59.0\n",
       "91    55.0  108.0     55.0\n",
       "92   108.0   56.0     50.0\n",
       "93   129.0   93.0     36.0\n",
       "94    50.0   50.0      7.0\n",
       "95    95.0  112.0    116.0\n",
       "96    38.0   34.0    120.0\n",
       "97    23.0   66.0     61.0\n",
       "98    45.0   49.0     50.0\n",
       "99     2.0   27.0     20.0\n",
       "\n",
       "[100 rows x 3 columns]"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_csv('./data.csv',\n",
    "#            index_col=0#第一列作为行索引\n",
    "#             header=None,\n",
    "            header=0\n",
    "           )"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "improving-championship",
   "metadata": {},
   "source": [
    "### excel(超过100万条数据就无法显示了)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "finished-disposal",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.to_excel('./data.xls')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "opened-electron",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>68</td>\n",
       "      <td>5</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>41</td>\n",
       "      <td>107</td>\n",
       "      <td>109</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>141</td>\n",
       "      <td>105</td>\n",
       "      <td>107</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>54</td>\n",
       "      <td>21</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>31</td>\n",
       "      <td>103</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>48</td>\n",
       "      <td>85</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>140</td>\n",
       "      <td>115</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>43</td>\n",
       "      <td>102</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>22</td>\n",
       "      <td>53</td>\n",
       "      <td>116</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>146</td>\n",
       "      <td>90</td>\n",
       "      <td>120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>28</td>\n",
       "      <td>61</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>68</td>\n",
       "      <td>61</td>\n",
       "      <td>85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>31</td>\n",
       "      <td>0</td>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>87</td>\n",
       "      <td>67</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>34</td>\n",
       "      <td>41</td>\n",
       "      <td>135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>42</td>\n",
       "      <td>105</td>\n",
       "      <td>126</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>113</td>\n",
       "      <td>91</td>\n",
       "      <td>136</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>52</td>\n",
       "      <td>139</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>88</td>\n",
       "      <td>4</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>44</td>\n",
       "      <td>55</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>22</td>\n",
       "      <td>21</td>\n",
       "      <td>21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>135</td>\n",
       "      <td>125</td>\n",
       "      <td>61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>97</td>\n",
       "      <td>60</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>144</td>\n",
       "      <td>143</td>\n",
       "      <td>125</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>144</td>\n",
       "      <td>45</td>\n",
       "      <td>52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>78</td>\n",
       "      <td>86</td>\n",
       "      <td>127</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>133</td>\n",
       "      <td>138</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>39</td>\n",
       "      <td>70</td>\n",
       "      <td>69</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>142</td>\n",
       "      <td>105</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>127</td>\n",
       "      <td>14</td>\n",
       "      <td>91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>95</td>\n",
       "      <td>65</td>\n",
       "      <td>88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>74</td>\n",
       "      <td>56</td>\n",
       "      <td>59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>122</td>\n",
       "      <td>2</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>115</td>\n",
       "      <td>128</td>\n",
       "      <td>138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>74</th>\n",
       "      <td>58</td>\n",
       "      <td>122</td>\n",
       "      <td>150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <td>133</td>\n",
       "      <td>102</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>80</td>\n",
       "      <td>115</td>\n",
       "      <td>77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>126</td>\n",
       "      <td>49</td>\n",
       "      <td>103</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>113</td>\n",
       "      <td>26</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>10</td>\n",
       "      <td>47</td>\n",
       "      <td>138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>45</td>\n",
       "      <td>106</td>\n",
       "      <td>79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>149</td>\n",
       "      <td>97</td>\n",
       "      <td>143</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>27</td>\n",
       "      <td>66</td>\n",
       "      <td>40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>11</td>\n",
       "      <td>73</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>77</td>\n",
       "      <td>112</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>85</th>\n",
       "      <td>105</td>\n",
       "      <td>137</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>86</th>\n",
       "      <td>115</td>\n",
       "      <td>90</td>\n",
       "      <td>113</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>113</td>\n",
       "      <td>70</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>135</td>\n",
       "      <td>49</td>\n",
       "      <td>73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89</th>\n",
       "      <td>2</td>\n",
       "      <td>128</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>90</th>\n",
       "      <td>137</td>\n",
       "      <td>15</td>\n",
       "      <td>59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>91</th>\n",
       "      <td>55</td>\n",
       "      <td>108</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92</th>\n",
       "      <td>108</td>\n",
       "      <td>56</td>\n",
       "      <td>50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93</th>\n",
       "      <td>129</td>\n",
       "      <td>93</td>\n",
       "      <td>36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>94</th>\n",
       "      <td>50</td>\n",
       "      <td>50</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>95</td>\n",
       "      <td>112</td>\n",
       "      <td>116</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>38</td>\n",
       "      <td>34</td>\n",
       "      <td>120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>23</td>\n",
       "      <td>66</td>\n",
       "      <td>61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>45</td>\n",
       "      <td>49</td>\n",
       "      <td>50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>2</td>\n",
       "      <td>27</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    python  math  english\n",
       "0       68     5       11\n",
       "1       41   107      109\n",
       "2      141   105      107\n",
       "3       54    21       82\n",
       "4       31   103        3\n",
       "5       48    85       89\n",
       "6      140   115       55\n",
       "7       43   102       96\n",
       "8       22    53      116\n",
       "9      146    90      120\n",
       "10      28    61      100\n",
       "11      68    61       85\n",
       "12      31     0      110\n",
       "13      87    67       20\n",
       "14      34    41      135\n",
       "15      42   105      126\n",
       "16     113    91      136\n",
       "17      52   139       29\n",
       "18      88     4       48\n",
       "19      44    55       12\n",
       "20      22    21       21\n",
       "21     135   125       61\n",
       "22      97    60       15\n",
       "23     144   143      125\n",
       "24     144    45       52\n",
       "25      78    86      127\n",
       "26     133   138       29\n",
       "27      39    70       69\n",
       "28     142   105       84\n",
       "29     127    14       91\n",
       "..     ...   ...      ...\n",
       "70      95    65       88\n",
       "71      74    56       59\n",
       "72     122     2       65\n",
       "73     115   128      138\n",
       "74      58   122      150\n",
       "75     133   102      104\n",
       "76      80   115       77\n",
       "77     126    49      103\n",
       "78     113    26       45\n",
       "79      10    47      138\n",
       "80      45   106       79\n",
       "81     149    97      143\n",
       "82      27    66       40\n",
       "83      11    73       84\n",
       "84      77   112       16\n",
       "85     105   137       11\n",
       "86     115    90      113\n",
       "87     113    70       54\n",
       "88     135    49       73\n",
       "89       2   128       11\n",
       "90     137    15       59\n",
       "91      55   108       55\n",
       "92     108    56       50\n",
       "93     129    93       36\n",
       "94      50    50        7\n",
       "95      95   112      116\n",
       "96      38    34      120\n",
       "97      23    66       61\n",
       "98      45    49       50\n",
       "99       2    27       20\n",
       "\n",
       "[100 rows x 3 columns]"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_excel('./data.xls',\n",
    "             index_col=0)#第一列作为行索引"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "tough-donna",
   "metadata": {},
   "source": [
    "### HDF5(读写速度特别快)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "sophisticated-republican",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'\\n⽬录就是HDF5中的group, 描述了数据集dataset的分类信息，通过group 有效的将多种dataset 进⾏管理和区分；\\n⽂件就是HDF5中的dataset, 表示的是具体的数据。\\n'"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'''\n",
    "HDF5是⼀个独特的技术套件，可以管理⾮常⼤和复杂的数据收集。\n",
    "HDF5，可以存储不同类型数据的⽂件格式，后缀通常是.h5，它的结构是层次性的。\n",
    "⼀个HDF5⽂件可以被看作是⼀个组包含了各类不同的数据集\n",
    "'''\n",
    "# 对于HDF5⽂件中的数据存储，有两个核⼼概念：group 和 dataset\n",
    "# dataset 代表数据集，⼀个⽂件当中可以存放不同种类的数据集，\n",
    "# 这些数据集如何管理，就⽤到了group,最直观的理解，可以参考我们的⽂件管理系统，不同的⽂件位于不同的⽬录下。\n",
    "'''\n",
    "⽬录就是HDF5中的group, 描述了数据集dataset的分类信息，通过group 有效的将多种dataset 进⾏管理和区分；\n",
    "⽂件就是HDF5中的dataset, 表示的是具体的数据。\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "binding-celtic",
   "metadata": {},
   "outputs": [],
   "source": [
    "df.to_hdf('./data.h5',key='score')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "legendary-sandwich",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>计算机</th>\n",
       "      <th>化工</th>\n",
       "      <th>生物</th>\n",
       "      <th>工程</th>\n",
       "      <th>教师</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>50</td>\n",
       "      <td>99</td>\n",
       "      <td>70</td>\n",
       "      <td>56</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>68</td>\n",
       "      <td>23</td>\n",
       "      <td>58</td>\n",
       "      <td>63</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>81</td>\n",
       "      <td>58</td>\n",
       "      <td>40</td>\n",
       "      <td>37</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>49</td>\n",
       "      <td>41</td>\n",
       "      <td>79</td>\n",
       "      <td>22</td>\n",
       "      <td>88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>94</td>\n",
       "      <td>15</td>\n",
       "      <td>63</td>\n",
       "      <td>93</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>26</td>\n",
       "      <td>18</td>\n",
       "      <td>93</td>\n",
       "      <td>37</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>22</td>\n",
       "      <td>10</td>\n",
       "      <td>66</td>\n",
       "      <td>49</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>23</td>\n",
       "      <td>77</td>\n",
       "      <td>91</td>\n",
       "      <td>99</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>58</td>\n",
       "      <td>37</td>\n",
       "      <td>91</td>\n",
       "      <td>94</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>65</td>\n",
       "      <td>32</td>\n",
       "      <td>52</td>\n",
       "      <td>99</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>20</td>\n",
       "      <td>90</td>\n",
       "      <td>80</td>\n",
       "      <td>15</td>\n",
       "      <td>86</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>13</td>\n",
       "      <td>53</td>\n",
       "      <td>74</td>\n",
       "      <td>81</td>\n",
       "      <td>95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>20</td>\n",
       "      <td>72</td>\n",
       "      <td>62</td>\n",
       "      <td>96</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>18</td>\n",
       "      <td>98</td>\n",
       "      <td>6</td>\n",
       "      <td>55</td>\n",
       "      <td>86</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>38</td>\n",
       "      <td>92</td>\n",
       "      <td>96</td>\n",
       "      <td>32</td>\n",
       "      <td>91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>68</td>\n",
       "      <td>19</td>\n",
       "      <td>93</td>\n",
       "      <td>64</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>83</td>\n",
       "      <td>17</td>\n",
       "      <td>27</td>\n",
       "      <td>62</td>\n",
       "      <td>83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>83</td>\n",
       "      <td>37</td>\n",
       "      <td>68</td>\n",
       "      <td>83</td>\n",
       "      <td>97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>10</td>\n",
       "      <td>27</td>\n",
       "      <td>71</td>\n",
       "      <td>8</td>\n",
       "      <td>67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>22</td>\n",
       "      <td>46</td>\n",
       "      <td>42</td>\n",
       "      <td>85</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>42</td>\n",
       "      <td>58</td>\n",
       "      <td>39</td>\n",
       "      <td>69</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>91</td>\n",
       "      <td>62</td>\n",
       "      <td>50</td>\n",
       "      <td>49</td>\n",
       "      <td>51</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>90</td>\n",
       "      <td>48</td>\n",
       "      <td>46</td>\n",
       "      <td>29</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>91</td>\n",
       "      <td>19</td>\n",
       "      <td>87</td>\n",
       "      <td>67</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>85</td>\n",
       "      <td>29</td>\n",
       "      <td>15</td>\n",
       "      <td>58</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>65</td>\n",
       "      <td>70</td>\n",
       "      <td>57</td>\n",
       "      <td>25</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>61</td>\n",
       "      <td>94</td>\n",
       "      <td>65</td>\n",
       "      <td>76</td>\n",
       "      <td>63</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>40</td>\n",
       "      <td>53</td>\n",
       "      <td>63</td>\n",
       "      <td>71</td>\n",
       "      <td>86</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>80</td>\n",
       "      <td>73</td>\n",
       "      <td>22</td>\n",
       "      <td>8</td>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>17</td>\n",
       "      <td>57</td>\n",
       "      <td>67</td>\n",
       "      <td>30</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>970</th>\n",
       "      <td>69</td>\n",
       "      <td>77</td>\n",
       "      <td>32</td>\n",
       "      <td>90</td>\n",
       "      <td>38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>971</th>\n",
       "      <td>29</td>\n",
       "      <td>79</td>\n",
       "      <td>79</td>\n",
       "      <td>11</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>972</th>\n",
       "      <td>69</td>\n",
       "      <td>28</td>\n",
       "      <td>67</td>\n",
       "      <td>54</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>973</th>\n",
       "      <td>31</td>\n",
       "      <td>11</td>\n",
       "      <td>39</td>\n",
       "      <td>40</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>974</th>\n",
       "      <td>56</td>\n",
       "      <td>64</td>\n",
       "      <td>6</td>\n",
       "      <td>24</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>975</th>\n",
       "      <td>58</td>\n",
       "      <td>41</td>\n",
       "      <td>61</td>\n",
       "      <td>9</td>\n",
       "      <td>21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>976</th>\n",
       "      <td>93</td>\n",
       "      <td>84</td>\n",
       "      <td>15</td>\n",
       "      <td>45</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>977</th>\n",
       "      <td>78</td>\n",
       "      <td>70</td>\n",
       "      <td>8</td>\n",
       "      <td>76</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>978</th>\n",
       "      <td>98</td>\n",
       "      <td>88</td>\n",
       "      <td>14</td>\n",
       "      <td>54</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>979</th>\n",
       "      <td>41</td>\n",
       "      <td>43</td>\n",
       "      <td>29</td>\n",
       "      <td>95</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>980</th>\n",
       "      <td>20</td>\n",
       "      <td>40</td>\n",
       "      <td>54</td>\n",
       "      <td>48</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>981</th>\n",
       "      <td>87</td>\n",
       "      <td>61</td>\n",
       "      <td>30</td>\n",
       "      <td>13</td>\n",
       "      <td>37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>982</th>\n",
       "      <td>74</td>\n",
       "      <td>58</td>\n",
       "      <td>99</td>\n",
       "      <td>18</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>983</th>\n",
       "      <td>9</td>\n",
       "      <td>27</td>\n",
       "      <td>72</td>\n",
       "      <td>94</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>984</th>\n",
       "      <td>58</td>\n",
       "      <td>84</td>\n",
       "      <td>67</td>\n",
       "      <td>72</td>\n",
       "      <td>77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>985</th>\n",
       "      <td>86</td>\n",
       "      <td>49</td>\n",
       "      <td>50</td>\n",
       "      <td>62</td>\n",
       "      <td>34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>986</th>\n",
       "      <td>86</td>\n",
       "      <td>85</td>\n",
       "      <td>55</td>\n",
       "      <td>17</td>\n",
       "      <td>81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>987</th>\n",
       "      <td>65</td>\n",
       "      <td>22</td>\n",
       "      <td>10</td>\n",
       "      <td>61</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>988</th>\n",
       "      <td>79</td>\n",
       "      <td>72</td>\n",
       "      <td>40</td>\n",
       "      <td>29</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>989</th>\n",
       "      <td>61</td>\n",
       "      <td>73</td>\n",
       "      <td>94</td>\n",
       "      <td>93</td>\n",
       "      <td>52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>990</th>\n",
       "      <td>80</td>\n",
       "      <td>45</td>\n",
       "      <td>19</td>\n",
       "      <td>27</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>991</th>\n",
       "      <td>86</td>\n",
       "      <td>97</td>\n",
       "      <td>94</td>\n",
       "      <td>72</td>\n",
       "      <td>49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>992</th>\n",
       "      <td>62</td>\n",
       "      <td>14</td>\n",
       "      <td>85</td>\n",
       "      <td>72</td>\n",
       "      <td>21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>993</th>\n",
       "      <td>84</td>\n",
       "      <td>39</td>\n",
       "      <td>6</td>\n",
       "      <td>31</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>994</th>\n",
       "      <td>91</td>\n",
       "      <td>14</td>\n",
       "      <td>79</td>\n",
       "      <td>18</td>\n",
       "      <td>52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>56</td>\n",
       "      <td>63</td>\n",
       "      <td>50</td>\n",
       "      <td>54</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>94</td>\n",
       "      <td>17</td>\n",
       "      <td>88</td>\n",
       "      <td>94</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>64</td>\n",
       "      <td>76</td>\n",
       "      <td>91</td>\n",
       "      <td>42</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>13</td>\n",
       "      <td>28</td>\n",
       "      <td>7</td>\n",
       "      <td>27</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>19</td>\n",
       "      <td>73</td>\n",
       "      <td>78</td>\n",
       "      <td>26</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     计算机  化工  生物  工程  教师\n",
       "0     50  99  70  56  15\n",
       "1     68  23  58  63   6\n",
       "2     81  58  40  37  99\n",
       "3     49  41  79  22  88\n",
       "4     94  15  63  93  75\n",
       "5     26  18  93  37  55\n",
       "6     22  10  66  49  96\n",
       "7     23  77  91  99  82\n",
       "8     58  37  91  94  13\n",
       "9     65  32  52  99  28\n",
       "10    20  90  80  15  86\n",
       "11    13  53  74  81  95\n",
       "12    20  72  62  96  65\n",
       "13    18  98   6  55  86\n",
       "14    38  92  96  32  91\n",
       "15    68  19  93  64  14\n",
       "16    83  17  27  62  83\n",
       "17    83  37  68  83  97\n",
       "18    10  27  71   8  67\n",
       "19    22  46  42  85  74\n",
       "20    42  58  39  69  90\n",
       "21    91  62  50  49  51\n",
       "22    90  48  46  29  84\n",
       "23    91  19  87  67  16\n",
       "24    85  29  15  58  70\n",
       "25    65  70  57  25  94\n",
       "26    61  94  65  76  63\n",
       "27    40  53  63  71  86\n",
       "28    80  73  22   8  93\n",
       "29    17  57  67  30  43\n",
       "..   ...  ..  ..  ..  ..\n",
       "970   69  77  32  90  38\n",
       "971   29  79  79  11  43\n",
       "972   69  28  67  54  76\n",
       "973   31  11  39  40  98\n",
       "974   56  64   6  24   7\n",
       "975   58  41  61   9  21\n",
       "976   93  84  15  45   8\n",
       "977   78  70   8  76  74\n",
       "978   98  88  14  54  55\n",
       "979   41  43  29  95   8\n",
       "980   20  40  54  48  55\n",
       "981   87  61  30  13  37\n",
       "982   74  58  99  18  60\n",
       "983    9  27  72  94  13\n",
       "984   58  84  67  72  77\n",
       "985   86  49  50  62  34\n",
       "986   86  85  55  17  81\n",
       "987   65  22  10  61  74\n",
       "988   79  72  40  29  98\n",
       "989   61  73  94  93  52\n",
       "990   80  45  19  27  71\n",
       "991   86  97  94  72  49\n",
       "992   62  14  85  72  21\n",
       "993   84  39   6  31  60\n",
       "994   91  14  79  18  52\n",
       "995   56  63  50  54  80\n",
       "996   94  17  88  94  46\n",
       "997   64  76  91  42  60\n",
       "998   13  28   7  27  54\n",
       "999   19  73  78  26  24\n",
       "\n",
       "[1000 rows x 5 columns]"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2 = pd.DataFrame(data=np.random.randint(6,100,size=(1000,5)),\n",
    "                  columns=['计算机','化工','生物','工程','教师'])\n",
    "df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "cultural-boring",
   "metadata": {},
   "outputs": [],
   "source": [
    "df2.to_hdf('./data.h5',key='salary')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "magnetic-witness",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>计算机</th>\n",
       "      <th>化工</th>\n",
       "      <th>生物</th>\n",
       "      <th>工程</th>\n",
       "      <th>教师</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>50</td>\n",
       "      <td>99</td>\n",
       "      <td>70</td>\n",
       "      <td>56</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>68</td>\n",
       "      <td>23</td>\n",
       "      <td>58</td>\n",
       "      <td>63</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>81</td>\n",
       "      <td>58</td>\n",
       "      <td>40</td>\n",
       "      <td>37</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>49</td>\n",
       "      <td>41</td>\n",
       "      <td>79</td>\n",
       "      <td>22</td>\n",
       "      <td>88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>94</td>\n",
       "      <td>15</td>\n",
       "      <td>63</td>\n",
       "      <td>93</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>26</td>\n",
       "      <td>18</td>\n",
       "      <td>93</td>\n",
       "      <td>37</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>22</td>\n",
       "      <td>10</td>\n",
       "      <td>66</td>\n",
       "      <td>49</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>23</td>\n",
       "      <td>77</td>\n",
       "      <td>91</td>\n",
       "      <td>99</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>58</td>\n",
       "      <td>37</td>\n",
       "      <td>91</td>\n",
       "      <td>94</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>65</td>\n",
       "      <td>32</td>\n",
       "      <td>52</td>\n",
       "      <td>99</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>20</td>\n",
       "      <td>90</td>\n",
       "      <td>80</td>\n",
       "      <td>15</td>\n",
       "      <td>86</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>13</td>\n",
       "      <td>53</td>\n",
       "      <td>74</td>\n",
       "      <td>81</td>\n",
       "      <td>95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>20</td>\n",
       "      <td>72</td>\n",
       "      <td>62</td>\n",
       "      <td>96</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>18</td>\n",
       "      <td>98</td>\n",
       "      <td>6</td>\n",
       "      <td>55</td>\n",
       "      <td>86</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>38</td>\n",
       "      <td>92</td>\n",
       "      <td>96</td>\n",
       "      <td>32</td>\n",
       "      <td>91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>68</td>\n",
       "      <td>19</td>\n",
       "      <td>93</td>\n",
       "      <td>64</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>83</td>\n",
       "      <td>17</td>\n",
       "      <td>27</td>\n",
       "      <td>62</td>\n",
       "      <td>83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>83</td>\n",
       "      <td>37</td>\n",
       "      <td>68</td>\n",
       "      <td>83</td>\n",
       "      <td>97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>10</td>\n",
       "      <td>27</td>\n",
       "      <td>71</td>\n",
       "      <td>8</td>\n",
       "      <td>67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>22</td>\n",
       "      <td>46</td>\n",
       "      <td>42</td>\n",
       "      <td>85</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>42</td>\n",
       "      <td>58</td>\n",
       "      <td>39</td>\n",
       "      <td>69</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>91</td>\n",
       "      <td>62</td>\n",
       "      <td>50</td>\n",
       "      <td>49</td>\n",
       "      <td>51</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>90</td>\n",
       "      <td>48</td>\n",
       "      <td>46</td>\n",
       "      <td>29</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>91</td>\n",
       "      <td>19</td>\n",
       "      <td>87</td>\n",
       "      <td>67</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>85</td>\n",
       "      <td>29</td>\n",
       "      <td>15</td>\n",
       "      <td>58</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>65</td>\n",
       "      <td>70</td>\n",
       "      <td>57</td>\n",
       "      <td>25</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>61</td>\n",
       "      <td>94</td>\n",
       "      <td>65</td>\n",
       "      <td>76</td>\n",
       "      <td>63</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>40</td>\n",
       "      <td>53</td>\n",
       "      <td>63</td>\n",
       "      <td>71</td>\n",
       "      <td>86</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>80</td>\n",
       "      <td>73</td>\n",
       "      <td>22</td>\n",
       "      <td>8</td>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>17</td>\n",
       "      <td>57</td>\n",
       "      <td>67</td>\n",
       "      <td>30</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>970</th>\n",
       "      <td>69</td>\n",
       "      <td>77</td>\n",
       "      <td>32</td>\n",
       "      <td>90</td>\n",
       "      <td>38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>971</th>\n",
       "      <td>29</td>\n",
       "      <td>79</td>\n",
       "      <td>79</td>\n",
       "      <td>11</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>972</th>\n",
       "      <td>69</td>\n",
       "      <td>28</td>\n",
       "      <td>67</td>\n",
       "      <td>54</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>973</th>\n",
       "      <td>31</td>\n",
       "      <td>11</td>\n",
       "      <td>39</td>\n",
       "      <td>40</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>974</th>\n",
       "      <td>56</td>\n",
       "      <td>64</td>\n",
       "      <td>6</td>\n",
       "      <td>24</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>975</th>\n",
       "      <td>58</td>\n",
       "      <td>41</td>\n",
       "      <td>61</td>\n",
       "      <td>9</td>\n",
       "      <td>21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>976</th>\n",
       "      <td>93</td>\n",
       "      <td>84</td>\n",
       "      <td>15</td>\n",
       "      <td>45</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>977</th>\n",
       "      <td>78</td>\n",
       "      <td>70</td>\n",
       "      <td>8</td>\n",
       "      <td>76</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>978</th>\n",
       "      <td>98</td>\n",
       "      <td>88</td>\n",
       "      <td>14</td>\n",
       "      <td>54</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>979</th>\n",
       "      <td>41</td>\n",
       "      <td>43</td>\n",
       "      <td>29</td>\n",
       "      <td>95</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>980</th>\n",
       "      <td>20</td>\n",
       "      <td>40</td>\n",
       "      <td>54</td>\n",
       "      <td>48</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>981</th>\n",
       "      <td>87</td>\n",
       "      <td>61</td>\n",
       "      <td>30</td>\n",
       "      <td>13</td>\n",
       "      <td>37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>982</th>\n",
       "      <td>74</td>\n",
       "      <td>58</td>\n",
       "      <td>99</td>\n",
       "      <td>18</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>983</th>\n",
       "      <td>9</td>\n",
       "      <td>27</td>\n",
       "      <td>72</td>\n",
       "      <td>94</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>984</th>\n",
       "      <td>58</td>\n",
       "      <td>84</td>\n",
       "      <td>67</td>\n",
       "      <td>72</td>\n",
       "      <td>77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>985</th>\n",
       "      <td>86</td>\n",
       "      <td>49</td>\n",
       "      <td>50</td>\n",
       "      <td>62</td>\n",
       "      <td>34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>986</th>\n",
       "      <td>86</td>\n",
       "      <td>85</td>\n",
       "      <td>55</td>\n",
       "      <td>17</td>\n",
       "      <td>81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>987</th>\n",
       "      <td>65</td>\n",
       "      <td>22</td>\n",
       "      <td>10</td>\n",
       "      <td>61</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>988</th>\n",
       "      <td>79</td>\n",
       "      <td>72</td>\n",
       "      <td>40</td>\n",
       "      <td>29</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>989</th>\n",
       "      <td>61</td>\n",
       "      <td>73</td>\n",
       "      <td>94</td>\n",
       "      <td>93</td>\n",
       "      <td>52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>990</th>\n",
       "      <td>80</td>\n",
       "      <td>45</td>\n",
       "      <td>19</td>\n",
       "      <td>27</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>991</th>\n",
       "      <td>86</td>\n",
       "      <td>97</td>\n",
       "      <td>94</td>\n",
       "      <td>72</td>\n",
       "      <td>49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>992</th>\n",
       "      <td>62</td>\n",
       "      <td>14</td>\n",
       "      <td>85</td>\n",
       "      <td>72</td>\n",
       "      <td>21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>993</th>\n",
       "      <td>84</td>\n",
       "      <td>39</td>\n",
       "      <td>6</td>\n",
       "      <td>31</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>994</th>\n",
       "      <td>91</td>\n",
       "      <td>14</td>\n",
       "      <td>79</td>\n",
       "      <td>18</td>\n",
       "      <td>52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>995</th>\n",
       "      <td>56</td>\n",
       "      <td>63</td>\n",
       "      <td>50</td>\n",
       "      <td>54</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>996</th>\n",
       "      <td>94</td>\n",
       "      <td>17</td>\n",
       "      <td>88</td>\n",
       "      <td>94</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>997</th>\n",
       "      <td>64</td>\n",
       "      <td>76</td>\n",
       "      <td>91</td>\n",
       "      <td>42</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>998</th>\n",
       "      <td>13</td>\n",
       "      <td>28</td>\n",
       "      <td>7</td>\n",
       "      <td>27</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>999</th>\n",
       "      <td>19</td>\n",
       "      <td>73</td>\n",
       "      <td>78</td>\n",
       "      <td>26</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1000 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     计算机  化工  生物  工程  教师\n",
       "0     50  99  70  56  15\n",
       "1     68  23  58  63   6\n",
       "2     81  58  40  37  99\n",
       "3     49  41  79  22  88\n",
       "4     94  15  63  93  75\n",
       "5     26  18  93  37  55\n",
       "6     22  10  66  49  96\n",
       "7     23  77  91  99  82\n",
       "8     58  37  91  94  13\n",
       "9     65  32  52  99  28\n",
       "10    20  90  80  15  86\n",
       "11    13  53  74  81  95\n",
       "12    20  72  62  96  65\n",
       "13    18  98   6  55  86\n",
       "14    38  92  96  32  91\n",
       "15    68  19  93  64  14\n",
       "16    83  17  27  62  83\n",
       "17    83  37  68  83  97\n",
       "18    10  27  71   8  67\n",
       "19    22  46  42  85  74\n",
       "20    42  58  39  69  90\n",
       "21    91  62  50  49  51\n",
       "22    90  48  46  29  84\n",
       "23    91  19  87  67  16\n",
       "24    85  29  15  58  70\n",
       "25    65  70  57  25  94\n",
       "26    61  94  65  76  63\n",
       "27    40  53  63  71  86\n",
       "28    80  73  22   8  93\n",
       "29    17  57  67  30  43\n",
       "..   ...  ..  ..  ..  ..\n",
       "970   69  77  32  90  38\n",
       "971   29  79  79  11  43\n",
       "972   69  28  67  54  76\n",
       "973   31  11  39  40  98\n",
       "974   56  64   6  24   7\n",
       "975   58  41  61   9  21\n",
       "976   93  84  15  45   8\n",
       "977   78  70   8  76  74\n",
       "978   98  88  14  54  55\n",
       "979   41  43  29  95   8\n",
       "980   20  40  54  48  55\n",
       "981   87  61  30  13  37\n",
       "982   74  58  99  18  60\n",
       "983    9  27  72  94  13\n",
       "984   58  84  67  72  77\n",
       "985   86  49  50  62  34\n",
       "986   86  85  55  17  81\n",
       "987   65  22  10  61  74\n",
       "988   79  72  40  29  98\n",
       "989   61  73  94  93  52\n",
       "990   80  45  19  27  71\n",
       "991   86  97  94  72  49\n",
       "992   62  14  85  72  21\n",
       "993   84  39   6  31  60\n",
       "994   91  14  79  18  52\n",
       "995   56  63  50  54  80\n",
       "996   94  17  88  94  46\n",
       "997   64  76  91  42  60\n",
       "998   13  28   7  27  54\n",
       "999   19  73  78  26  24\n",
       "\n",
       "[1000 rows x 5 columns]"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_hdf('./data.h5',key='salary')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "handmade-relevance",
   "metadata": {},
   "source": [
    "### SQL（中型以上公司一定会用sql）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "million-distributor",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sqlalchemy import create_engine  #数据库引擎\n",
    "#在终端进入mysql命令：mysql -uroot -p19900416"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "seventh-thousand",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 数据库连接\n",
    "engine = create_engine('mysql+pymysql://root:19900416@localhost/pandas?charset=UTF8MB4')\n",
    "# pandas----是数据库\n",
    "# ?-----是表示属性"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "loving-pipeline",
   "metadata": {},
   "outputs": [],
   "source": [
    "df2.to_sql('salary',engine,index=False) #保存到mysql"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "challenging-spare",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>计算机</th>\n",
       "      <th>化工</th>\n",
       "      <th>生物</th>\n",
       "      <th>工程</th>\n",
       "      <th>教师</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>50</td>\n",
       "      <td>99</td>\n",
       "      <td>70</td>\n",
       "      <td>56</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>68</td>\n",
       "      <td>23</td>\n",
       "      <td>58</td>\n",
       "      <td>63</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>81</td>\n",
       "      <td>58</td>\n",
       "      <td>40</td>\n",
       "      <td>37</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>49</td>\n",
       "      <td>41</td>\n",
       "      <td>79</td>\n",
       "      <td>22</td>\n",
       "      <td>88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>94</td>\n",
       "      <td>15</td>\n",
       "      <td>63</td>\n",
       "      <td>93</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>26</td>\n",
       "      <td>18</td>\n",
       "      <td>93</td>\n",
       "      <td>37</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>22</td>\n",
       "      <td>10</td>\n",
       "      <td>66</td>\n",
       "      <td>49</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>23</td>\n",
       "      <td>77</td>\n",
       "      <td>91</td>\n",
       "      <td>99</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>58</td>\n",
       "      <td>37</td>\n",
       "      <td>91</td>\n",
       "      <td>94</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>65</td>\n",
       "      <td>32</td>\n",
       "      <td>52</td>\n",
       "      <td>99</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>20</td>\n",
       "      <td>90</td>\n",
       "      <td>80</td>\n",
       "      <td>15</td>\n",
       "      <td>86</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>13</td>\n",
       "      <td>53</td>\n",
       "      <td>74</td>\n",
       "      <td>81</td>\n",
       "      <td>95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>20</td>\n",
       "      <td>72</td>\n",
       "      <td>62</td>\n",
       "      <td>96</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>18</td>\n",
       "      <td>98</td>\n",
       "      <td>6</td>\n",
       "      <td>55</td>\n",
       "      <td>86</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>38</td>\n",
       "      <td>92</td>\n",
       "      <td>96</td>\n",
       "      <td>32</td>\n",
       "      <td>91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>68</td>\n",
       "      <td>19</td>\n",
       "      <td>93</td>\n",
       "      <td>64</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>83</td>\n",
       "      <td>17</td>\n",
       "      <td>27</td>\n",
       "      <td>62</td>\n",
       "      <td>83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>83</td>\n",
       "      <td>37</td>\n",
       "      <td>68</td>\n",
       "      <td>83</td>\n",
       "      <td>97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>10</td>\n",
       "      <td>27</td>\n",
       "      <td>71</td>\n",
       "      <td>8</td>\n",
       "      <td>67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>22</td>\n",
       "      <td>46</td>\n",
       "      <td>42</td>\n",
       "      <td>85</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>42</td>\n",
       "      <td>58</td>\n",
       "      <td>39</td>\n",
       "      <td>69</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>91</td>\n",
       "      <td>62</td>\n",
       "      <td>50</td>\n",
       "      <td>49</td>\n",
       "      <td>51</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>90</td>\n",
       "      <td>48</td>\n",
       "      <td>46</td>\n",
       "      <td>29</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>91</td>\n",
       "      <td>19</td>\n",
       "      <td>87</td>\n",
       "      <td>67</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>85</td>\n",
       "      <td>29</td>\n",
       "      <td>15</td>\n",
       "      <td>58</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>65</td>\n",
       "      <td>70</td>\n",
       "      <td>57</td>\n",
       "      <td>25</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>61</td>\n",
       "      <td>94</td>\n",
       "      <td>65</td>\n",
       "      <td>76</td>\n",
       "      <td>63</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>40</td>\n",
       "      <td>53</td>\n",
       "      <td>63</td>\n",
       "      <td>71</td>\n",
       "      <td>86</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>80</td>\n",
       "      <td>73</td>\n",
       "      <td>22</td>\n",
       "      <td>8</td>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>17</td>\n",
       "      <td>57</td>\n",
       "      <td>67</td>\n",
       "      <td>30</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>32</td>\n",
       "      <td>68</td>\n",
       "      <td>20</td>\n",
       "      <td>92</td>\n",
       "      <td>44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>65</td>\n",
       "      <td>78</td>\n",
       "      <td>39</td>\n",
       "      <td>47</td>\n",
       "      <td>41</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>33</td>\n",
       "      <td>93</td>\n",
       "      <td>34</td>\n",
       "      <td>26</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>99</td>\n",
       "      <td>64</td>\n",
       "      <td>80</td>\n",
       "      <td>8</td>\n",
       "      <td>77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>51</td>\n",
       "      <td>73</td>\n",
       "      <td>99</td>\n",
       "      <td>39</td>\n",
       "      <td>67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>35</th>\n",
       "      <td>18</td>\n",
       "      <td>92</td>\n",
       "      <td>84</td>\n",
       "      <td>20</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>39</td>\n",
       "      <td>96</td>\n",
       "      <td>94</td>\n",
       "      <td>73</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>37</th>\n",
       "      <td>68</td>\n",
       "      <td>86</td>\n",
       "      <td>35</td>\n",
       "      <td>56</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>38</th>\n",
       "      <td>20</td>\n",
       "      <td>96</td>\n",
       "      <td>82</td>\n",
       "      <td>36</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>87</td>\n",
       "      <td>56</td>\n",
       "      <td>55</td>\n",
       "      <td>70</td>\n",
       "      <td>24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>43</td>\n",
       "      <td>23</td>\n",
       "      <td>53</td>\n",
       "      <td>94</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>35</td>\n",
       "      <td>17</td>\n",
       "      <td>23</td>\n",
       "      <td>91</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>42</th>\n",
       "      <td>38</td>\n",
       "      <td>32</td>\n",
       "      <td>62</td>\n",
       "      <td>7</td>\n",
       "      <td>51</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>98</td>\n",
       "      <td>46</td>\n",
       "      <td>87</td>\n",
       "      <td>45</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>65</td>\n",
       "      <td>74</td>\n",
       "      <td>20</td>\n",
       "      <td>66</td>\n",
       "      <td>40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>45</th>\n",
       "      <td>38</td>\n",
       "      <td>55</td>\n",
       "      <td>33</td>\n",
       "      <td>97</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>46</th>\n",
       "      <td>57</td>\n",
       "      <td>54</td>\n",
       "      <td>65</td>\n",
       "      <td>33</td>\n",
       "      <td>41</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>47</th>\n",
       "      <td>95</td>\n",
       "      <td>13</td>\n",
       "      <td>18</td>\n",
       "      <td>6</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>48</th>\n",
       "      <td>87</td>\n",
       "      <td>52</td>\n",
       "      <td>61</td>\n",
       "      <td>94</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>49</th>\n",
       "      <td>63</td>\n",
       "      <td>52</td>\n",
       "      <td>62</td>\n",
       "      <td>26</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    计算机  化工  生物  工程  教师\n",
       "0    50  99  70  56  15\n",
       "1    68  23  58  63   6\n",
       "2    81  58  40  37  99\n",
       "3    49  41  79  22  88\n",
       "4    94  15  63  93  75\n",
       "5    26  18  93  37  55\n",
       "6    22  10  66  49  96\n",
       "7    23  77  91  99  82\n",
       "8    58  37  91  94  13\n",
       "9    65  32  52  99  28\n",
       "10   20  90  80  15  86\n",
       "11   13  53  74  81  95\n",
       "12   20  72  62  96  65\n",
       "13   18  98   6  55  86\n",
       "14   38  92  96  32  91\n",
       "15   68  19  93  64  14\n",
       "16   83  17  27  62  83\n",
       "17   83  37  68  83  97\n",
       "18   10  27  71   8  67\n",
       "19   22  46  42  85  74\n",
       "20   42  58  39  69  90\n",
       "21   91  62  50  49  51\n",
       "22   90  48  46  29  84\n",
       "23   91  19  87  67  16\n",
       "24   85  29  15  58  70\n",
       "25   65  70  57  25  94\n",
       "26   61  94  65  76  63\n",
       "27   40  53  63  71  86\n",
       "28   80  73  22   8  93\n",
       "29   17  57  67  30  43\n",
       "30   32  68  20  92  44\n",
       "31   65  78  39  47  41\n",
       "32   33  93  34  26  45\n",
       "33   99  64  80   8  77\n",
       "34   51  73  99  39  67\n",
       "35   18  92  84  20  17\n",
       "36   39  96  94  73  80\n",
       "37   68  86  35  56  80\n",
       "38   20  96  82  36  82\n",
       "39   87  56  55  70  24\n",
       "40   43  23  53  94  15\n",
       "41   35  17  23  91  99\n",
       "42   38  32  62   7  51\n",
       "43   98  46  87  45  14\n",
       "44   65  74  20  66  40\n",
       "45   38  55  33  97  99\n",
       "46   57  54  65  33  41\n",
       "47   95  13  18   6  90\n",
       "48   87  52  61  94  35\n",
       "49   63  52  62  26  60"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df3 = pd.read_sql('select * from salary limit 50',engine)\n",
    "df3"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "modular-straight",
   "metadata": {},
   "source": [
    "## 数据选取"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "artificial-bacon",
   "metadata": {},
   "source": [
    "### 获取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "fewer-murray",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>24</td>\n",
       "      <td>148</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>32</td>\n",
       "      <td>27</td>\n",
       "      <td>106</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>52</td>\n",
       "      <td>26</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>116</td>\n",
       "      <td>131</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>105</td>\n",
       "      <td>122</td>\n",
       "      <td>102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>20</td>\n",
       "      <td>88</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>52</td>\n",
       "      <td>39</td>\n",
       "      <td>112</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>70</td>\n",
       "      <td>94</td>\n",
       "      <td>51</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>98</td>\n",
       "      <td>16</td>\n",
       "      <td>141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>91</td>\n",
       "      <td>145</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   python  math  english\n",
       "A      24   148      104\n",
       "B      32    27      106\n",
       "C      52    26       87\n",
       "D     116   131        4\n",
       "E     105   122      102\n",
       "F      20    88       26\n",
       "G      52    39      112\n",
       "H      70    94       51\n",
       "I      98    16      141\n",
       "J      91   145       87"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,151,size =(10,3)),\n",
    "                   index=list('ABCDEFGHIJ'),\n",
    "                   columns=['python','math','english'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "balanced-biodiversity",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A     24\n",
       "B     32\n",
       "C     52\n",
       "D    116\n",
       "E    105\n",
       "F     20\n",
       "G     52\n",
       "H     70\n",
       "I     98\n",
       "J     91\n",
       "Name: python, dtype: int32"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['python']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "spectacular-scale",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>english</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>24</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>32</td>\n",
       "      <td>106</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>52</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>116</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>105</td>\n",
       "      <td>102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>20</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>52</td>\n",
       "      <td>112</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>70</td>\n",
       "      <td>51</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>98</td>\n",
       "      <td>141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>91</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   python  english\n",
       "A      24      104\n",
       "B      32      106\n",
       "C      52       87\n",
       "D     116        4\n",
       "E     105      102\n",
       "F      20       26\n",
       "G      52      112\n",
       "H      70       51\n",
       "I      98      141\n",
       "J      91       87"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[['python','english']]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cutting-hostel",
   "metadata": {},
   "source": [
    "### 标签选择(即行索引)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "experienced-decimal",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "python      24\n",
       "math       148\n",
       "english    104\n",
       "Name: A, dtype: int32"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc['A']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "overhead-generation",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "d:\\python3.7.3\\lib\\site-packages\\ipykernel_launcher.py:1: FutureWarning: \n",
      "Passing list-likes to .loc or [] with any missing label will raise\n",
      "KeyError in the future, you can use .reindex() as an alternative.\n",
      "\n",
      "See the documentation here:\n",
      "https://pandas.pydata.org/pandas-docs/stable/indexing.html#deprecate-loc-reindex-listlike\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>24.0</td>\n",
       "      <td>148.0</td>\n",
       "      <td>104.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>20.0</td>\n",
       "      <td>88.0</td>\n",
       "      <td>26.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   python   math  english\n",
       "A    24.0  148.0    104.0\n",
       "F    20.0   88.0     26.0\n",
       "K     NaN    NaN      NaN"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[['A','F','K']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "furnished-stage",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "24"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc['A','python']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "boring-information",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A    24\n",
       "C    52\n",
       "F    20\n",
       "Name: python, dtype: int32"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[['A','C','F'],'python']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "finite-makeup",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>english</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>24</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>52</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>105</td>\n",
       "      <td>102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>52</td>\n",
       "      <td>112</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>98</td>\n",
       "      <td>141</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   python  english\n",
       "A      24      104\n",
       "C      52       87\n",
       "E     105      102\n",
       "G      52      112\n",
       "I      98      141"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc['A'::2,['python','english']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "smart-closer",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>24</td>\n",
       "      <td>148</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>32</td>\n",
       "      <td>27</td>\n",
       "      <td>106</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>52</td>\n",
       "      <td>26</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>116</td>\n",
       "      <td>131</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   python  math  english\n",
       "A      24   148      104\n",
       "B      32    27      106\n",
       "C      52    26       87\n",
       "D     116   131        4"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc['A':'D',:]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "confused-warrant",
   "metadata": {},
   "source": [
    "### 位置选择"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "smaller-slovenia",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "python      24\n",
       "math       148\n",
       "english    104\n",
       "Name: A, dtype: int32"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "desirable-joseph",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>24</td>\n",
       "      <td>148</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>52</td>\n",
       "      <td>26</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>105</td>\n",
       "      <td>122</td>\n",
       "      <td>102</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   python  math  english\n",
       "A      24   148      104\n",
       "C      52    26       87\n",
       "E     105   122      102"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[[0,2,4]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "damaged-movement",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>english</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>24</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>32</td>\n",
       "      <td>106</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>52</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>116</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   python  english\n",
       "A      24      104\n",
       "B      32      106\n",
       "C      52       87\n",
       "D     116        4"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[0:4,[0,2]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "center-austin",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>116</td>\n",
       "      <td>131</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>20</td>\n",
       "      <td>88</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>70</td>\n",
       "      <td>94</td>\n",
       "      <td>51</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   python  math  english\n",
       "D     116   131        4\n",
       "F      20    88       26\n",
       "H      70    94       51"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[3:8:2]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "conceptual-participant",
   "metadata": {},
   "source": [
    "### boolean索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "regional-acrylic",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>116</td>\n",
       "      <td>131</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>105</td>\n",
       "      <td>122</td>\n",
       "      <td>102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>98</td>\n",
       "      <td>16</td>\n",
       "      <td>141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>91</td>\n",
       "      <td>145</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   python  math  english\n",
       "D     116   131        4\n",
       "E     105   122      102\n",
       "I      98    16      141\n",
       "J      91   145       87"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cond = df.python>80  #获取python大于80的\n",
    "df[cond]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "chemical-monitoring",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A     True\n",
       "B    False\n",
       "C    False\n",
       "D     True\n",
       "E     True\n",
       "F    False\n",
       "G    False\n",
       "H    False\n",
       "I     True\n",
       "J     True\n",
       "dtype: bool"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cond = df.mean(axis=1) >75 \n",
    "cond"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "massive-listening",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>24</td>\n",
       "      <td>148</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>116</td>\n",
       "      <td>131</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>105</td>\n",
       "      <td>122</td>\n",
       "      <td>102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>98</td>\n",
       "      <td>16</td>\n",
       "      <td>141</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>91</td>\n",
       "      <td>145</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   python  math  english\n",
       "A      24   148      104\n",
       "D     116   131        4\n",
       "E     105   122      102\n",
       "I      98    16      141\n",
       "J      91   145       87"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[cond]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "iraqi-indication",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>116</td>\n",
       "      <td>131</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>105</td>\n",
       "      <td>122</td>\n",
       "      <td>102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>91</td>\n",
       "      <td>145</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   python  math  english\n",
       "D     116   131        4\n",
       "E     105   122      102\n",
       "J      91   145       87"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "con = (df.python >70) & (df.math >70)\n",
    "df[con]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "simplified-communications",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>52</td>\n",
       "      <td>26</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>105</td>\n",
       "      <td>122</td>\n",
       "      <td>102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>70</td>\n",
       "      <td>94</td>\n",
       "      <td>51</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   python  math  english\n",
       "C      52    26       87\n",
       "E     105   122      102\n",
       "H      70    94       51"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "con4 = df.index.isin(['C','E','H','K'])  #判断数据是否在这个列表里\n",
    "df[con4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "functional-bloom",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "cognitive-motion",
   "metadata": {},
   "source": [
    "### 赋值操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "forty-prize",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "24"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['python']['A']\n",
    "# df['A']['python']   -这个不可以"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "younger-sunglasses",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "150"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#修改某的位置的值\n",
    "df['python']['A'] =150\n",
    "df['python']['A']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "id": "dependent-laundry",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "      <th>jave</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>150</td>\n",
       "      <td>148</td>\n",
       "      <td>104</td>\n",
       "      <td>41</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>32</td>\n",
       "      <td>27</td>\n",
       "      <td>106</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>52</td>\n",
       "      <td>26</td>\n",
       "      <td>87</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>116</td>\n",
       "      <td>131</td>\n",
       "      <td>4</td>\n",
       "      <td>78</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>105</td>\n",
       "      <td>122</td>\n",
       "      <td>102</td>\n",
       "      <td>47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>20</td>\n",
       "      <td>88</td>\n",
       "      <td>26</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>52</td>\n",
       "      <td>39</td>\n",
       "      <td>112</td>\n",
       "      <td>128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>70</td>\n",
       "      <td>94</td>\n",
       "      <td>51</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>98</td>\n",
       "      <td>16</td>\n",
       "      <td>141</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>91</td>\n",
       "      <td>145</td>\n",
       "      <td>87</td>\n",
       "      <td>79</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   python  math  english  jave\n",
       "A     150   148      104    41\n",
       "B      32    27      106    17\n",
       "C      52    26       87    98\n",
       "D     116   131        4    78\n",
       "E     105   122      102    47\n",
       "F      20    88       26     4\n",
       "G      52    39      112   128\n",
       "H      70    94       51    94\n",
       "I      98    16      141    55\n",
       "J      91   145       87    79"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#新增加一列\n",
    "df['jave'] =np.random.randint(0,151,size=10)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "specific-dependence",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "      <th>jave</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>150</td>\n",
       "      <td>148</td>\n",
       "      <td>104</td>\n",
       "      <td>41</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>32</td>\n",
       "      <td>27</td>\n",
       "      <td>106</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>52</td>\n",
       "      <td>147</td>\n",
       "      <td>87</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>116</td>\n",
       "      <td>147</td>\n",
       "      <td>4</td>\n",
       "      <td>78</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>105</td>\n",
       "      <td>147</td>\n",
       "      <td>102</td>\n",
       "      <td>47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>20</td>\n",
       "      <td>88</td>\n",
       "      <td>26</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>52</td>\n",
       "      <td>39</td>\n",
       "      <td>112</td>\n",
       "      <td>128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>70</td>\n",
       "      <td>94</td>\n",
       "      <td>51</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>98</td>\n",
       "      <td>16</td>\n",
       "      <td>141</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>91</td>\n",
       "      <td>145</td>\n",
       "      <td>87</td>\n",
       "      <td>79</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   python  math  english  jave\n",
       "A     150   148      104    41\n",
       "B      32    27      106    17\n",
       "C      52   147       87    98\n",
       "D     116   147        4    78\n",
       "E     105   147      102    47\n",
       "F      20    88       26     4\n",
       "G      52    39      112   128\n",
       "H      70    94       51    94\n",
       "I      98    16      141    55\n",
       "J      91   145       87    79"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[['C','D','E'],'math']=147  #修改多个人的成绩\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "electoral-combining",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "      <th>jave</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>150</td>\n",
       "      <td>148</td>\n",
       "      <td>104</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>60</td>\n",
       "      <td>60</td>\n",
       "      <td>106</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>60</td>\n",
       "      <td>147</td>\n",
       "      <td>87</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>116</td>\n",
       "      <td>147</td>\n",
       "      <td>60</td>\n",
       "      <td>78</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>105</td>\n",
       "      <td>147</td>\n",
       "      <td>102</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>60</td>\n",
       "      <td>88</td>\n",
       "      <td>60</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>60</td>\n",
       "      <td>60</td>\n",
       "      <td>112</td>\n",
       "      <td>128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>70</td>\n",
       "      <td>94</td>\n",
       "      <td>60</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>98</td>\n",
       "      <td>60</td>\n",
       "      <td>141</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>91</td>\n",
       "      <td>145</td>\n",
       "      <td>87</td>\n",
       "      <td>79</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   python  math  english  jave\n",
       "A     150   148      104    60\n",
       "B      60    60      106    60\n",
       "C      60   147       87    98\n",
       "D     116   147       60    78\n",
       "E     105   147      102    60\n",
       "F      60    88       60    60\n",
       "G      60    60      112   128\n",
       "H      70    94       60    94\n",
       "I      98    60      141    60\n",
       "J      91   145       87    79"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cond = df <60\n",
    "df[cond] = 60      #符合该条件的值修改，不符合则不改变，类似np.where\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "id": "burning-moment",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "      <th>jave</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>150</td>\n",
       "      <td>148</td>\n",
       "      <td>104</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>60</td>\n",
       "      <td>60</td>\n",
       "      <td>106</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>60</td>\n",
       "      <td>147</td>\n",
       "      <td>87</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>216</td>\n",
       "      <td>147</td>\n",
       "      <td>160</td>\n",
       "      <td>78</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>105</td>\n",
       "      <td>147</td>\n",
       "      <td>102</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>60</td>\n",
       "      <td>88</td>\n",
       "      <td>60</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>160</td>\n",
       "      <td>60</td>\n",
       "      <td>212</td>\n",
       "      <td>128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>70</td>\n",
       "      <td>94</td>\n",
       "      <td>60</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>98</td>\n",
       "      <td>60</td>\n",
       "      <td>141</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>191</td>\n",
       "      <td>145</td>\n",
       "      <td>187</td>\n",
       "      <td>79</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   python  math  english  jave\n",
       "A     150   148      104    60\n",
       "B      60    60      106    60\n",
       "C      60   147       87    98\n",
       "D     216   147      160    78\n",
       "E     105   147      102    60\n",
       "F      60    88       60    60\n",
       "G     160    60      212   128\n",
       "H      70    94       60    94\n",
       "I      98    60      141    60\n",
       "J     191   145      187    79"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[3::3,[0,2]] += 100\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "anticipated-light",
   "metadata": {},
   "source": [
    "## 数据集成(将series和dataframe对象组合在一起)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "presidential-submission",
   "metadata": {},
   "source": [
    "### concat数据串联"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "earned-juice",
   "metadata": {},
   "outputs": [],
   "source": [
    "df1 = pd.DataFrame(data = np.random.randint(0,151,size =(10,3)),\n",
    "                   index=list('ABCDEFGHIJ'),\n",
    "                   columns=['python','math','english'])\n",
    "df2 = pd.DataFrame(data = np.random.randint(0,151,size =(10,3)),\n",
    "                   index=list('KLMNOPQRST'),\n",
    "                   columns=['python','math','english'])\n",
    "df3 =  pd.DataFrame(data = np.random.randint(0,151,size =(10,2)),\n",
    "                   index=list('ABCDEFGHIJ'),\n",
    "                   columns=['java','chinese'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "portable-glenn",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>53</td>\n",
       "      <td>46</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>77</td>\n",
       "      <td>8</td>\n",
       "      <td>85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>92</td>\n",
       "      <td>146</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>147</td>\n",
       "      <td>105</td>\n",
       "      <td>150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>85</td>\n",
       "      <td>103</td>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>39</td>\n",
       "      <td>54</td>\n",
       "      <td>81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>87</td>\n",
       "      <td>106</td>\n",
       "      <td>101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>111</td>\n",
       "      <td>65</td>\n",
       "      <td>133</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>19</td>\n",
       "      <td>18</td>\n",
       "      <td>61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>20</td>\n",
       "      <td>113</td>\n",
       "      <td>121</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>107</td>\n",
       "      <td>23</td>\n",
       "      <td>86</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>133</td>\n",
       "      <td>65</td>\n",
       "      <td>57</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>120</td>\n",
       "      <td>3</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>104</td>\n",
       "      <td>120</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>92</td>\n",
       "      <td>125</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>100</td>\n",
       "      <td>107</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>83</td>\n",
       "      <td>82</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>87</td>\n",
       "      <td>6</td>\n",
       "      <td>122</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>49</td>\n",
       "      <td>121</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>106</td>\n",
       "      <td>82</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   python  math  english\n",
       "A      53    46       65\n",
       "B      77     8       85\n",
       "C      92   146       94\n",
       "D     147   105      150\n",
       "E      85   103      110\n",
       "F      39    54       81\n",
       "G      87   106      101\n",
       "H     111    65      133\n",
       "I      19    18       61\n",
       "J      20   113      121\n",
       "K     107    23       86\n",
       "L     133    65       57\n",
       "M     120     3       80\n",
       "N     104   120       42\n",
       "O      92   125       15\n",
       "P     100   107       20\n",
       "Q      83    82       99\n",
       "R      87     6      122\n",
       "S      49   121        1\n",
       "T     106    82        7"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([df1,df2]) #axis = 0默认，行增加"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "senior-reasoning",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "      <th>java</th>\n",
       "      <th>chinese</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>53</td>\n",
       "      <td>46</td>\n",
       "      <td>65</td>\n",
       "      <td>22</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>77</td>\n",
       "      <td>8</td>\n",
       "      <td>85</td>\n",
       "      <td>112</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>92</td>\n",
       "      <td>146</td>\n",
       "      <td>94</td>\n",
       "      <td>118</td>\n",
       "      <td>115</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>147</td>\n",
       "      <td>105</td>\n",
       "      <td>150</td>\n",
       "      <td>79</td>\n",
       "      <td>149</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>85</td>\n",
       "      <td>103</td>\n",
       "      <td>110</td>\n",
       "      <td>16</td>\n",
       "      <td>102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>39</td>\n",
       "      <td>54</td>\n",
       "      <td>81</td>\n",
       "      <td>39</td>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>87</td>\n",
       "      <td>106</td>\n",
       "      <td>101</td>\n",
       "      <td>39</td>\n",
       "      <td>135</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>111</td>\n",
       "      <td>65</td>\n",
       "      <td>133</td>\n",
       "      <td>120</td>\n",
       "      <td>63</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>19</td>\n",
       "      <td>18</td>\n",
       "      <td>61</td>\n",
       "      <td>136</td>\n",
       "      <td>39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>20</td>\n",
       "      <td>113</td>\n",
       "      <td>121</td>\n",
       "      <td>144</td>\n",
       "      <td>115</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   python  math  english  java  chinese\n",
       "A      53    46       65    22       12\n",
       "B      77     8       85   112       46\n",
       "C      92   146       94   118      115\n",
       "D     147   105      150    79      149\n",
       "E      85   103      110    16      102\n",
       "F      39    54       81    39      110\n",
       "G      87   106      101    39      135\n",
       "H     111    65      133   120       63\n",
       "I      19    18       61   136       39\n",
       "J      20   113      121   144      115"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.concat([df1,df3],axis = 1) #axis = 1,列增加"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "widespread-wednesday",
   "metadata": {},
   "source": [
    "### 数据插入"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "chubby-emperor",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>53</td>\n",
       "      <td>46</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>77</td>\n",
       "      <td>8</td>\n",
       "      <td>85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>92</td>\n",
       "      <td>146</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>147</td>\n",
       "      <td>105</td>\n",
       "      <td>150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>85</td>\n",
       "      <td>103</td>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>39</td>\n",
       "      <td>54</td>\n",
       "      <td>81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>87</td>\n",
       "      <td>106</td>\n",
       "      <td>101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>111</td>\n",
       "      <td>65</td>\n",
       "      <td>133</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>19</td>\n",
       "      <td>18</td>\n",
       "      <td>61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>20</td>\n",
       "      <td>113</td>\n",
       "      <td>121</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   python  math  english\n",
       "A      53    46       65\n",
       "B      77     8       85\n",
       "C      92   146       94\n",
       "D     147   105      150\n",
       "E      85   103      110\n",
       "F      39    54       81\n",
       "G      87   106      101\n",
       "H     111    65      133\n",
       "I      19    18       61\n",
       "J      20   113      121"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "social-seminar",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>C++</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>53</td>\n",
       "      <td>131</td>\n",
       "      <td>46</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>77</td>\n",
       "      <td>115</td>\n",
       "      <td>8</td>\n",
       "      <td>85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>92</td>\n",
       "      <td>51</td>\n",
       "      <td>146</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>147</td>\n",
       "      <td>120</td>\n",
       "      <td>105</td>\n",
       "      <td>150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>85</td>\n",
       "      <td>98</td>\n",
       "      <td>103</td>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>39</td>\n",
       "      <td>74</td>\n",
       "      <td>54</td>\n",
       "      <td>81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>87</td>\n",
       "      <td>121</td>\n",
       "      <td>106</td>\n",
       "      <td>101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>111</td>\n",
       "      <td>17</td>\n",
       "      <td>65</td>\n",
       "      <td>133</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>19</td>\n",
       "      <td>83</td>\n",
       "      <td>18</td>\n",
       "      <td>61</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>20</td>\n",
       "      <td>36</td>\n",
       "      <td>113</td>\n",
       "      <td>121</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   python  C++  math  english\n",
       "A      53  131    46       65\n",
       "B      77  115     8       85\n",
       "C      92   51   146       94\n",
       "D     147  120   105      150\n",
       "E      85   98   103      110\n",
       "F      39   74    54       81\n",
       "G      87  121   106      101\n",
       "H     111   17    65      133\n",
       "I      19   83    18       61\n",
       "J      20   36   113      121"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#插入一列\n",
    "df1.insert(loc = 1,#插入位置\n",
    "           column='C++',#插入列名\n",
    "           value=np.random.randint(0,151,size=10))\n",
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "polished-ground",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "d:\\python3.7.3\\lib\\site-packages\\pandas\\core\\frame.py:6692: FutureWarning: Sorting because non-concatenation axis is not aligned. A future version\n",
      "of pandas will change to not sort by default.\n",
      "\n",
      "To accept the future behavior, pass 'sort=False'.\n",
      "\n",
      "To retain the current behavior and silence the warning, pass 'sort=True'.\n",
      "\n",
      "  sort=sort)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>C++</th>\n",
       "      <th>english</th>\n",
       "      <th>math</th>\n",
       "      <th>python</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>131.0</td>\n",
       "      <td>65</td>\n",
       "      <td>46</td>\n",
       "      <td>53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>115.0</td>\n",
       "      <td>85</td>\n",
       "      <td>8</td>\n",
       "      <td>77</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>51.0</td>\n",
       "      <td>94</td>\n",
       "      <td>146</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>120.0</td>\n",
       "      <td>150</td>\n",
       "      <td>105</td>\n",
       "      <td>147</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>98.0</td>\n",
       "      <td>110</td>\n",
       "      <td>103</td>\n",
       "      <td>85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>74.0</td>\n",
       "      <td>81</td>\n",
       "      <td>54</td>\n",
       "      <td>39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>121.0</td>\n",
       "      <td>101</td>\n",
       "      <td>106</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>17.0</td>\n",
       "      <td>133</td>\n",
       "      <td>65</td>\n",
       "      <td>111</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>83.0</td>\n",
       "      <td>61</td>\n",
       "      <td>18</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>36.0</td>\n",
       "      <td>121</td>\n",
       "      <td>113</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>NaN</td>\n",
       "      <td>86</td>\n",
       "      <td>23</td>\n",
       "      <td>107</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>NaN</td>\n",
       "      <td>57</td>\n",
       "      <td>65</td>\n",
       "      <td>133</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>NaN</td>\n",
       "      <td>80</td>\n",
       "      <td>3</td>\n",
       "      <td>120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>NaN</td>\n",
       "      <td>42</td>\n",
       "      <td>120</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>NaN</td>\n",
       "      <td>15</td>\n",
       "      <td>125</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>NaN</td>\n",
       "      <td>20</td>\n",
       "      <td>107</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>NaN</td>\n",
       "      <td>99</td>\n",
       "      <td>82</td>\n",
       "      <td>83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>NaN</td>\n",
       "      <td>122</td>\n",
       "      <td>6</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>NaN</td>\n",
       "      <td>1</td>\n",
       "      <td>121</td>\n",
       "      <td>49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>NaN</td>\n",
       "      <td>7</td>\n",
       "      <td>82</td>\n",
       "      <td>106</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     C++  english  math  python\n",
       "A  131.0       65    46      53\n",
       "B  115.0       85     8      77\n",
       "C   51.0       94   146      92\n",
       "D  120.0      150   105     147\n",
       "E   98.0      110   103      85\n",
       "F   74.0       81    54      39\n",
       "G  121.0      101   106      87\n",
       "H   17.0      133    65     111\n",
       "I   83.0       61    18      19\n",
       "J   36.0      121   113      20\n",
       "K    NaN       86    23     107\n",
       "L    NaN       57    65     133\n",
       "M    NaN       80     3     120\n",
       "N    NaN       42   120     104\n",
       "O    NaN       15   125      92\n",
       "P    NaN       20   107     100\n",
       "Q    NaN       99    82      83\n",
       "R    NaN      122     6      87\n",
       "S    NaN        1   121      49\n",
       "T    NaN        7    82     106"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1.append(df2) #在行后直接追加"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "id": "fatal-steps",
   "metadata": {},
   "outputs": [],
   "source": [
    " #concat 和 append如果索引不一致，会插入空数据"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "olympic-colors",
   "metadata": {},
   "source": [
    "### join SQL风格合并"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "active-success",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 表⼀中记录的是name和体重信息\n",
    "df1 = pd.DataFrame(data = {'name': ['softpo','Daniel','Brandon','Ella'],'weight':[70,55,75,65]})\n",
    "# 表⼆中记录的是name和身⾼信息\n",
    "df2 = pd.DataFrame(data = {'name': ['softpo','Daniel','Brandon','Cindy'],'height':[172,170,170,166]})\n",
    "df3 = pd.DataFrame(data = {'名字': ['softpo','Daniel','Brandon','Cindy'],'salary':[172,170,170,166]})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "id": "selective-monitor",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>weight</th>\n",
       "      <th>height</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>softpo</td>\n",
       "      <td>70</td>\n",
       "      <td>172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Daniel</td>\n",
       "      <td>55</td>\n",
       "      <td>170</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Brandon</td>\n",
       "      <td>75</td>\n",
       "      <td>170</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      name  weight  height\n",
       "0   softpo      70     172\n",
       "1   Daniel      55     170\n",
       "2  Brandon      75     170"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 根据共同的name将俩表的数据，进⾏合并\n",
    "pd.merge(df1,df2)            #两表合并，合并共同的交集,默认是inner，内合并"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "id": "stretch-provincial",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>weight</th>\n",
       "      <th>height</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>softpo</td>\n",
       "      <td>70.0</td>\n",
       "      <td>172.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Daniel</td>\n",
       "      <td>55.0</td>\n",
       "      <td>170.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Brandon</td>\n",
       "      <td>75.0</td>\n",
       "      <td>170.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Ella</td>\n",
       "      <td>65.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Cindy</td>\n",
       "      <td>NaN</td>\n",
       "      <td>166.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      name  weight  height\n",
       "0   softpo    70.0   172.0\n",
       "1   Daniel    55.0   170.0\n",
       "2  Brandon    75.0   170.0\n",
       "3     Ella    65.0     NaN\n",
       "4    Cindy     NaN   166.0"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.merge(df1,df2,how='outer')  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "id": "micro-watson",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>weight</th>\n",
       "      <th>height</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>softpo</td>\n",
       "      <td>70</td>\n",
       "      <td>172.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Daniel</td>\n",
       "      <td>55</td>\n",
       "      <td>170.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Brandon</td>\n",
       "      <td>75</td>\n",
       "      <td>170.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Ella</td>\n",
       "      <td>65</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      name  weight  height\n",
       "0   softpo      70   172.0\n",
       "1   Daniel      55   170.0\n",
       "2  Brandon      75   170.0\n",
       "3     Ella      65     NaN"
      ]
     },
     "execution_count": 96,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.merge(df1,df2,how='left')  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "id": "generic-ability",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>name</th>\n",
       "      <th>weight</th>\n",
       "      <th>名字</th>\n",
       "      <th>height</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>softpo</td>\n",
       "      <td>70</td>\n",
       "      <td>softpo</td>\n",
       "      <td>172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Daniel</td>\n",
       "      <td>55</td>\n",
       "      <td>Daniel</td>\n",
       "      <td>170</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Brandon</td>\n",
       "      <td>75</td>\n",
       "      <td>Brandon</td>\n",
       "      <td>170</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      name  weight       名字  height\n",
       "0   softpo      70   softpo     172\n",
       "1   Daniel      55   Daniel     170\n",
       "2  Brandon      75  Brandon     170"
      ]
     },
     "execution_count": 98,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.merge(df1,df3,left_on = 'name',right_on='名字')  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "id": "interpreted-costume",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>109</td>\n",
       "      <td>92</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>63</td>\n",
       "      <td>6</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>44</td>\n",
       "      <td>24</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>130</td>\n",
       "      <td>47</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>2</td>\n",
       "      <td>57</td>\n",
       "      <td>38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>98</td>\n",
       "      <td>104</td>\n",
       "      <td>107</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>24</td>\n",
       "      <td>38</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>39</td>\n",
       "      <td>142</td>\n",
       "      <td>50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>27</td>\n",
       "      <td>56</td>\n",
       "      <td>148</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>114</td>\n",
       "      <td>30</td>\n",
       "      <td>44</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   python  math  english\n",
       "A     109    92        3\n",
       "B      63     6      100\n",
       "C      44    24        7\n",
       "D     130    47       70\n",
       "E       2    57       38\n",
       "F      98   104      107\n",
       "G      24    38       55\n",
       "H      39   142       50\n",
       "I      27    56      148\n",
       "J     114    30       44"
      ]
     },
     "execution_count": 103,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df4 = pd.DataFrame(data=np.random.randint(0,151,size=(10,3)),\n",
    "                  index = list('ABCDEFGHIJ'),\n",
    "                  columns=['python','math','english'])\n",
    "df4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "id": "regulation-reach",
   "metadata": {},
   "outputs": [],
   "source": [
    "score_mean = df.mean(axis=1).round(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "id": "driving-elder",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "cannot insert 平均分, already exists",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-109-3c6c825bc71e>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mdf4\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0minsert\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mloc\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mcolumn\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'平均分'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mvalue\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mscore_mean\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      2\u001b[0m \u001b[0mdf4\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32md:\\python3.7.3\\lib\\site-packages\\pandas\\core\\frame.py\u001b[0m in \u001b[0;36minsert\u001b[1;34m(self, loc, column, value, allow_duplicates)\u001b[0m\n\u001b[0;32m   3471\u001b[0m         \u001b[0mvalue\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_sanitize_column\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mcolumn\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbroadcast\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   3472\u001b[0m         self._data.insert(loc, column, value,\n\u001b[1;32m-> 3473\u001b[1;33m                           allow_duplicates=allow_duplicates)\n\u001b[0m\u001b[0;32m   3474\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   3475\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0massign\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32md:\\python3.7.3\\lib\\site-packages\\pandas\\core\\internals\\managers.py\u001b[0m in \u001b[0;36minsert\u001b[1;34m(self, loc, item, value, allow_duplicates)\u001b[0m\n\u001b[0;32m   1147\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0mallow_duplicates\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mitem\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1148\u001b[0m             \u001b[1;31m# Should this be a different kind of error??\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1149\u001b[1;33m             \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'cannot insert {}, already exists'\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mformat\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mitem\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1150\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1151\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[0misinstance\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mloc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mint\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mValueError\u001b[0m: cannot insert 平均分, already exists"
     ]
    }
   ],
   "source": [
    "df4.insert(loc=3,column='平均分',value=score_mean)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "id": "immediate-japan",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>math</th>\n",
       "      <th>english</th>\n",
       "      <th>平均分</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>109</td>\n",
       "      <td>92</td>\n",
       "      <td>3</td>\n",
       "      <td>115.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>63</td>\n",
       "      <td>6</td>\n",
       "      <td>100</td>\n",
       "      <td>71.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>44</td>\n",
       "      <td>24</td>\n",
       "      <td>7</td>\n",
       "      <td>98.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>130</td>\n",
       "      <td>47</td>\n",
       "      <td>70</td>\n",
       "      <td>150.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>2</td>\n",
       "      <td>57</td>\n",
       "      <td>38</td>\n",
       "      <td>103.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>98</td>\n",
       "      <td>104</td>\n",
       "      <td>107</td>\n",
       "      <td>67.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>G</th>\n",
       "      <td>24</td>\n",
       "      <td>38</td>\n",
       "      <td>55</td>\n",
       "      <td>140.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>39</td>\n",
       "      <td>142</td>\n",
       "      <td>50</td>\n",
       "      <td>79.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>27</td>\n",
       "      <td>56</td>\n",
       "      <td>148</td>\n",
       "      <td>89.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>114</td>\n",
       "      <td>30</td>\n",
       "      <td>44</td>\n",
       "      <td>150.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   python  math  english    平均分\n",
       "A     109    92        3  115.5\n",
       "B      63     6      100   71.5\n",
       "C      44    24        7   98.0\n",
       "D     130    47       70  150.2\n",
       "E       2    57       38  103.5\n",
       "F      98   104      107   67.0\n",
       "G      24    38       55  140.0\n",
       "H      39   142       50   79.5\n",
       "I      27    56      148   89.8\n",
       "J     114    30       44  150.5"
      ]
     },
     "execution_count": 110,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "id": "elementary-frederick",
   "metadata": {},
   "outputs": [],
   "source": [
    "df5 = df4.iloc[:,[0,1,3]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "id": "several-freeware",
   "metadata": {},
   "outputs": [],
   "source": [
    "score_mean.name = '平均分' ###如果series没有名字不能直接跟dataframe合并，会报错，需要先命名"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "id": "polar-photographer",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>python</th>\n",
       "      <th>math</th>\n",
       "      <th>平均分</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>109</td>\n",
       "      <td>92</td>\n",
       "      <td>115.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>63</td>\n",
       "      <td>6</td>\n",
       "      <td>71.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>44</td>\n",
       "      <td>24</td>\n",
       "      <td>98.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>130</td>\n",
       "      <td>47</td>\n",
       "      <td>150.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2</td>\n",
       "      <td>57</td>\n",
       "      <td>103.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>98</td>\n",
       "      <td>104</td>\n",
       "      <td>67.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>24</td>\n",
       "      <td>38</td>\n",
       "      <td>140.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>39</td>\n",
       "      <td>142</td>\n",
       "      <td>79.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>27</td>\n",
       "      <td>56</td>\n",
       "      <td>89.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>114</td>\n",
       "      <td>30</td>\n",
       "      <td>150.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   python  math    平均分\n",
       "0     109    92  115.5\n",
       "1      63     6   71.5\n",
       "2      44    24   98.0\n",
       "3     130    47  150.2\n",
       "4       2    57  103.5\n",
       "5      98   104   67.0\n",
       "6      24    38  140.0\n",
       "7      39   142   79.5\n",
       "8      27    56   89.8\n",
       "9     114    30  150.5"
      ]
     },
     "execution_count": 115,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.merge(df5,score_mean,\n",
    "        left_index=True,#说明数据合并根据行索引对应？？\n",
    "        right_index=True#说明右边的数据合并根据行索引对应？？？\n",
    "        )"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "covered-input",
   "metadata": {},
   "source": [
    "## 数据清洗"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "id": "boxed-holmes",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>color</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>red</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>blue</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>red</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>green</td>\n",
       "      <td>15.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>blue</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>red</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   color  price\n",
       "0    red   10.0\n",
       "1   blue   20.0\n",
       "2    red   10.0\n",
       "3  green   15.0\n",
       "4   blue   20.0\n",
       "5   None    0.0\n",
       "6    red    NaN"
      ]
     },
     "execution_count": 117,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = {'color': ['red','blue','red','green','blue',None,'red'],\n",
    " 'price':[10,20,10,15,20,0,np.NaN]})\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "id": "designing-butler",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>color</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>red</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>blue</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>green</td>\n",
       "      <td>15.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>red</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   color  price\n",
       "0    red   10.0\n",
       "1   blue   20.0\n",
       "3  green   15.0\n",
       "5   None    0.0\n",
       "6    red    NaN"
      ]
     },
     "execution_count": 120,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1、重复数据过滤\n",
    "df.drop_duplicates() # 删除重复数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "id": "overall-script",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    False\n",
       "1    False\n",
       "2     True\n",
       "3    False\n",
       "4     True\n",
       "5    False\n",
       "6    False\n",
       "dtype: bool"
      ]
     },
     "execution_count": 119,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.duplicated() # 判断是否存在重复数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "id": "aggressive-geology",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>color</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   color  price\n",
       "0  False  False\n",
       "1  False  False\n",
       "2  False  False\n",
       "3  False  False\n",
       "4  False  False\n",
       "5   True  False\n",
       "6  False   True"
      ]
     },
     "execution_count": 125,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2、空数据过滤\n",
    "df.isnull() # 判断是否存在空数据，存在返回True，否则返回False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "id": "champion-flood",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>color</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>red</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>blue</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>red</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>green</td>\n",
       "      <td>15.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>blue</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   color  price\n",
       "0    red   10.0\n",
       "1   blue   20.0\n",
       "2    red   10.0\n",
       "3  green   15.0\n",
       "4   blue   20.0"
      ]
     },
     "execution_count": 123,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.dropna(how = 'any') # 删除空数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "id": "jewish-address",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>color</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>red</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>blue</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>red</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>green</td>\n",
       "      <td>15.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>blue</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1111</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>red</td>\n",
       "      <td>1111.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   color   price\n",
       "0    red    10.0\n",
       "1   blue    20.0\n",
       "2    red    10.0\n",
       "3  green    15.0\n",
       "4   blue    20.0\n",
       "5   1111     0.0\n",
       "6    red  1111.0"
      ]
     },
     "execution_count": 124,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.fillna(value=1111) # 填充空数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "id": "balanced-enclosure",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 3、指定⾏或者列过滤\n",
    "del df['color'] # 直接删除某列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "id": "practical-construction",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>15.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   price\n",
       "0   10.0\n",
       "1   20.0\n",
       "3   15.0\n",
       "5    0.0"
      ]
     },
     "execution_count": 130,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#删除指定行或列\n",
    "df.drop(labels=[2,4,6]) #默认删除行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "id": "helpful-seven",
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "\"['color'] not found in axis\"",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-131-2c0f939f106f>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mdf\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdrop\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlabels\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'color'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0maxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m#删除列\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32md:\\python3.7.3\\lib\\site-packages\\pandas\\core\\frame.py\u001b[0m in \u001b[0;36mdrop\u001b[1;34m(self, labels, axis, index, columns, level, inplace, errors)\u001b[0m\n\u001b[0;32m   3938\u001b[0m                                            \u001b[0mindex\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mindex\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcolumns\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   3939\u001b[0m                                            \u001b[0mlevel\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlevel\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0minplace\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0minplace\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 3940\u001b[1;33m                                            errors=errors)\n\u001b[0m\u001b[0;32m   3941\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   3942\u001b[0m     @rewrite_axis_style_signature('mapper', [('copy', True),\n",
      "\u001b[1;32md:\\python3.7.3\\lib\\site-packages\\pandas\\core\\generic.py\u001b[0m in \u001b[0;36mdrop\u001b[1;34m(self, labels, axis, index, columns, level, inplace, errors)\u001b[0m\n\u001b[0;32m   3778\u001b[0m         \u001b[1;32mfor\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlabels\u001b[0m \u001b[1;32min\u001b[0m \u001b[0maxes\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mitems\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   3779\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mlabels\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mnot\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 3780\u001b[1;33m                 \u001b[0mobj\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mobj\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_drop_axis\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlabels\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlevel\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlevel\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0merrors\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0merrors\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   3781\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   3782\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0minplace\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32md:\\python3.7.3\\lib\\site-packages\\pandas\\core\\generic.py\u001b[0m in \u001b[0;36m_drop_axis\u001b[1;34m(self, labels, axis, level, errors)\u001b[0m\n\u001b[0;32m   3810\u001b[0m                 \u001b[0mnew_axis\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdrop\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlabels\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlevel\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mlevel\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0merrors\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0merrors\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   3811\u001b[0m             \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 3812\u001b[1;33m                 \u001b[0mnew_axis\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0maxis\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdrop\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlabels\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0merrors\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0merrors\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   3813\u001b[0m             \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mreindex\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m**\u001b[0m\u001b[1;33m{\u001b[0m\u001b[0maxis_name\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mnew_axis\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   3814\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32md:\\python3.7.3\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36mdrop\u001b[1;34m(self, labels, errors)\u001b[0m\n\u001b[0;32m   4963\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0merrors\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[1;34m'ignore'\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   4964\u001b[0m                 raise KeyError(\n\u001b[1;32m-> 4965\u001b[1;33m                     '{} not found in axis'.format(labels[mask]))\n\u001b[0m\u001b[0;32m   4966\u001b[0m             \u001b[0mindexer\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mindexer\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m~\u001b[0m\u001b[0mmask\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   4967\u001b[0m         \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdelete\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mindexer\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mKeyError\u001b[0m: \"['color'] not found in axis\""
     ]
    }
   ],
   "source": [
    "df.drop(labels=['color'],axis=1) #删除列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "id": "domestic-insert",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>China</th>\n",
       "      <th>France</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>dog</th>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cat</th>\n",
       "      <td>2</td>\n",
       "      <td>256</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     China  France\n",
       "dog      3       1\n",
       "cat      2     256"
      ]
     },
     "execution_count": 135,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 4、函数filter使⽤\n",
    "df = pd.DataFrame(np.array(([3,7,1], [2, 8, 256])),\n",
    " index=['dog', 'cat'],\n",
    " columns=['China', 'America', 'France'])\n",
    "df.filter(items=['China', 'France'])#保留数据，china，france，原始数据没有变"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 139,
   "id": "norwegian-silence",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>China</th>\n",
       "      <th>America</th>\n",
       "      <th>France</th>\n",
       "      <th>size</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>dog</th>\n",
       "      <td>3</td>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "      <td>1024</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cat</th>\n",
       "      <td>2</td>\n",
       "      <td>8</td>\n",
       "      <td>256</td>\n",
       "      <td>1024</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     China  America  France  size\n",
       "dog      3        7       1  1024\n",
       "cat      2        8     256  1024"
      ]
     },
     "execution_count": 139,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['size']=1024\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "id": "green-stocks",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>China</th>\n",
       "      <th>America</th>\n",
       "      <th>size</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>dog</th>\n",
       "      <td>3</td>\n",
       "      <td>7</td>\n",
       "      <td>1024</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cat</th>\n",
       "      <td>2</td>\n",
       "      <td>8</td>\n",
       "      <td>1024</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     China  America  size\n",
       "dog      3        7  1024\n",
       "cat      2        8  1024"
      ]
     },
     "execution_count": 143,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选择⾏中包含og\n",
    "df.filter(like='i', axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "id": "spiritual-table",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>China</th>\n",
       "      <th>America</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>dog</th>\n",
       "      <td>3</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cat</th>\n",
       "      <td>2</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     China  America\n",
       "dog      3        7\n",
       "cat      2        8"
      ]
     },
     "execution_count": 133,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 5.根据正则表达式删选列标签\n",
    "df.filter(regex='a$', axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "id": "blond-massachusetts",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>China</th>\n",
       "      <th>America</th>\n",
       "      <th>size</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>dog</th>\n",
       "      <td>3</td>\n",
       "      <td>7</td>\n",
       "      <td>1024</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>cat</th>\n",
       "      <td>2</td>\n",
       "      <td>8</td>\n",
       "      <td>1024</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     China  America  size\n",
       "dog      3        7  1024\n",
       "cat      2        8  1024"
      ]
     },
     "execution_count": 142,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "id": "norwegian-onion",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 6、异常值过滤\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 148,
   "id": "several-guard",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([395, 149, 165, 185, 442, 692, 497, 293, 411, 578, 678, 172, 375,\n",
       "       215, 299, 409, 742, 475, 679, 336, 269, 313, 307, 112, 791, 490,\n",
       "       555, 309, 714, 288, 293, 241, 106, 738, 198, 326, 757, 330, 635,\n",
       "       159, 781, 664, 497, 511, 764, 555, 467, 507, 354, 526, 108, 714,\n",
       "       123, 629, 508, 715, 576, 767, 243, 330, 267, 735, 209, 709, 443,\n",
       "       352, 581, 347, 795, 377, 448, 199, 676, 196, 210, 445, 477, 564,\n",
       "       497, 104, 603, 163, 220, 153, 767, 198, 562, 513, 409, 553, 481,\n",
       "       399, 616, 789, 164, 781, 662, 743, 614, 463, 767, 227, 349, 220,\n",
       "       569, 762, 592, 199, 720, 651, 537, 161, 150, 446, 295, 231, 580,\n",
       "       112, 307, 659, 174, 284, 522, 418, 713, 766, 446, 240, 326, 664,\n",
       "       122, 191, 728, 256, 476])"
      ]
     },
     "execution_count": 148,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = np.random.randint(0,1000,size=200)\n",
    "cond = (a<=800) & (a>=100)\n",
    "a[cond]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "finished-closing",
   "metadata": {},
   "outputs": [],
   "source": [
    "df2 = pd.DataFrame(data = np.random.randn(10000,3)) # 正态分布数据\n",
    "# 3σ过滤异常值，σ即是标准差\n",
    "cond = (df2 > 3*df2.std()).any(axis = 1)\n",
    "index = df2[cond].index # 不满⾜条件的⾏索引\n",
    "df2.drop(labels=index,axis = 0) # 根据⾏索引，进⾏数据删除"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "elect-student",
   "metadata": {},
   "source": [
    "## 数据转换"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "annual-beauty",
   "metadata": {},
   "source": [
    "### 轴和元素转换"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 150,
   "id": "collected-submission",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>8</td>\n",
       "      <td>1</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>8</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>1</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>3</td>\n",
       "      <td>8</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A       8           1      7\n",
       "B       9           9      1\n",
       "C       1           4      9\n",
       "D       4           0      1\n",
       "E       8           7      0\n",
       "F       1           9      0\n",
       "H       5           0      2\n",
       "I       4           0      2\n",
       "J       0           2      8\n",
       "K       3           8      8"
      ]
     },
     "execution_count": 150,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,10,size = (10,3)),\n",
    " index = list('ABCDEFHIJK'),\n",
    " columns=['Python','Tensorflow','Keras'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 151,
   "id": "alternate-cabinet",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>⼈⼯智能</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>AA</th>\n",
       "      <td>8</td>\n",
       "      <td>1</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>BB</th>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>8</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>1</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>3</td>\n",
       "      <td>8</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    ⼈⼯智能  Tensorflow  Keras\n",
       "AA     8           1      7\n",
       "BB     9           9      1\n",
       "C      1           4      9\n",
       "D      4           0      1\n",
       "E      8           7      0\n",
       "F      1           9      0\n",
       "H      5           0      2\n",
       "I      4           0      2\n",
       "J      0           2      8\n",
       "K      3           8      8"
      ]
     },
     "execution_count": 151,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#1、重命名轴索引\n",
    "df.rename(index = {'A':'AA','B':'BB'},columns = {'Python':'⼈⼯智能'},inplace=True)#是否替换原数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 152,
   "id": "convinced-german",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>8</td>\n",
       "      <td>1</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>8</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>1</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>3</td>\n",
       "      <td>8</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A       8           1      7\n",
       "B       9           9      1\n",
       "C       1           4      9\n",
       "D       4           0      1\n",
       "E       8           7      0\n",
       "F       1           9      0\n",
       "H       5           0      2\n",
       "I       4           0      2\n",
       "J       0           2      8\n",
       "K       3           8      8"
      ]
     },
     "execution_count": 152,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2、替换值?????????????\n",
    "df.replace(3,1024) #将3替换为1024\n",
    "df.replace([0,7],2048) # 将0和7替换为2048\n",
    "df.replace({0:512,np.nan:998}) # 根据字典键值对进⾏替换\n",
    "df.replace({'Python':2},-1024) # 将Python这⼀列中等于2的，替换为-1024"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "handmade-punch",
   "metadata": {},
   "source": [
    "### map Series元素改变"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 153,
   "id": "verbal-condition",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A       AI\n",
       "B    Hello\n",
       "C      NaN\n",
       "D    Hello\n",
       "E      NaN\n",
       "F      NaN\n",
       "H      NaN\n",
       "I      NaN\n",
       "J      NaN\n",
       "K      NaN\n",
       "Name: Keras, dtype: object"
      ]
     },
     "execution_count": 153,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1、map批量元素改变，Series专有,只能针对一列；没有对应数据返回空\n",
    "df['Keras'].map({1:'Hello',5:'World',7:'AI'}) # 字典映射"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 154,
   "id": "impaired-tattoo",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A     True\n",
       "B     True\n",
       "C    False\n",
       "D    False\n",
       "E     True\n",
       "F    False\n",
       "H     True\n",
       "I    False\n",
       "J    False\n",
       "K    False\n",
       "Name: Python, dtype: bool"
      ]
     },
     "execution_count": 154,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['Python'].map(lambda x:True if x >=5 else False) # 隐式函数映射\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "id": "plain-invite",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "      <th>level</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>8</td>\n",
       "      <td>1</td>\n",
       "      <td>7</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>9</td>\n",
       "      <td>9</td>\n",
       "      <td>1</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>9</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>8</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>1</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>8</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>3</td>\n",
       "      <td>8</td>\n",
       "      <td>8</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras  level\n",
       "A       8           1      7  False\n",
       "B       9           9      1   True\n",
       "C       1           4      9  False\n",
       "D       4           0      1   True\n",
       "E       8           7      0  False\n",
       "F       1           9      0   True\n",
       "H       5           0      2   True\n",
       "I       4           0      2   True\n",
       "J       0           2      8   None\n",
       "K       3           8      8   None"
      ]
     },
     "execution_count": 158,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def convert(x): # 显示函数映射\n",
    " if x%3 == 0:\n",
    "     return True\n",
    " elif x%3 == 1:\n",
    "     return False\n",
    "df['level'] = df['Tensorflow'].map(convert)\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "third-mumbai",
   "metadata": {},
   "source": [
    "### apply元素改变。既⽀持 Series，也⽀持 DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 160,
   "id": "employed-cricket",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A    108\n",
       "B    109\n",
       "C    101\n",
       "D    104\n",
       "E    108\n",
       "F    101\n",
       "H    105\n",
       "I    104\n",
       "J    100\n",
       "K    103\n",
       "Name: Python, dtype: int64"
      ]
     },
     "execution_count": 160,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['Python'].apply(lambda x: x+100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 161,
   "id": "humanitarian-smith",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A    1\n",
       "B    1\n",
       "C    1\n",
       "D    1\n",
       "E    1\n",
       "F    1\n",
       "H    1\n",
       "I    1\n",
       "J    0\n",
       "K    1\n",
       "Name: Python, dtype: int64"
      ]
     },
     "execution_count": 161,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['Python'].apply(lambda x: 1 if x else 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 162,
   "id": "ready-panic",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "      <th>level</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>1008</td>\n",
       "      <td>1001</td>\n",
       "      <td>1007</td>\n",
       "      <td>1000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>1009</td>\n",
       "      <td>1009</td>\n",
       "      <td>1001</td>\n",
       "      <td>1001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>1001</td>\n",
       "      <td>1004</td>\n",
       "      <td>1009</td>\n",
       "      <td>1000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>1004</td>\n",
       "      <td>1000</td>\n",
       "      <td>1001</td>\n",
       "      <td>1001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>1008</td>\n",
       "      <td>1007</td>\n",
       "      <td>1000</td>\n",
       "      <td>1000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>1001</td>\n",
       "      <td>1009</td>\n",
       "      <td>1000</td>\n",
       "      <td>1001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>1005</td>\n",
       "      <td>1000</td>\n",
       "      <td>1002</td>\n",
       "      <td>1001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>1004</td>\n",
       "      <td>1000</td>\n",
       "      <td>1002</td>\n",
       "      <td>1001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>1000</td>\n",
       "      <td>1002</td>\n",
       "      <td>1008</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>1003</td>\n",
       "      <td>1008</td>\n",
       "      <td>1008</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras level\n",
       "A    1008        1001   1007  1000\n",
       "B    1009        1009   1001  1001\n",
       "C    1001        1004   1009  1000\n",
       "D    1004        1000   1001  1001\n",
       "E    1008        1007   1000  1000\n",
       "F    1001        1009   1000  1001\n",
       "H    1005        1000   1002  1001\n",
       "I    1004        1000   1002  1001\n",
       "J    1000        1002   1008   NaN\n",
       "K    1003        1008   1008   NaN"
      ]
     },
     "execution_count": 162,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.apply(lambda x: x+1000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 174,
   "id": "central-sugar",
   "metadata": {},
   "outputs": [],
   "source": [
    "del df['level']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 176,
   "id": "accomplished-louisville",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python        (4.3, 10)\n",
       "Tensorflow    (4.0, 10)\n",
       "Keras         (3.8, 10)\n",
       "dtype: object"
      ]
     },
     "execution_count": 176,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def convert(x):\n",
    "    return (x.mean(),x.count())\n",
    "df.apply(convert)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 177,
   "id": "lucky-calibration",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A     (5.333333333333333, 3)\n",
       "B     (6.333333333333333, 3)\n",
       "C     (4.666666666666667, 3)\n",
       "D    (1.6666666666666667, 3)\n",
       "E                   (5.0, 3)\n",
       "F    (3.3333333333333335, 3)\n",
       "H    (2.3333333333333335, 3)\n",
       "I                   (2.0, 3)\n",
       "J    (3.3333333333333335, 3)\n",
       "K     (6.333333333333333, 3)\n",
       "dtype: object"
      ]
     },
     "execution_count": 177,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.apply(convert,axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "overall-nancy",
   "metadata": {},
   "source": [
    "### transform\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 178,
   "id": "private-conviction",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,10,size = (10,3)),\n",
    " index = list('ABCDEFHIJK'),\n",
    " columns=['Python','Tensorflow','Keras'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 179,
   "id": "trying-wagon",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A   -1024\n",
       "B   -1024\n",
       "C   -1024\n",
       "D    1024\n",
       "E    1024\n",
       "F   -1024\n",
       "H   -1024\n",
       "I    1024\n",
       "J    1024\n",
       "K   -1024\n",
       "Name: Python, dtype: int64"
      ]
     },
     "execution_count": 179,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['Python'].transform(lambda x: 1024 if x>5 else -1024)  #此操作与map、apply类似"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 180,
   "id": "naked-theater",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sqrt</th>\n",
       "      <th>exp</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>2.000000</td>\n",
       "      <td>54.598150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>1.414214</td>\n",
       "      <td>7.389056</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>1.414214</td>\n",
       "      <td>7.389056</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>3.000000</td>\n",
       "      <td>8103.083928</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>2.828427</td>\n",
       "      <td>2980.957987</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>1.414214</td>\n",
       "      <td>7.389056</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>2.236068</td>\n",
       "      <td>148.413159</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>2.449490</td>\n",
       "      <td>403.428793</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>2.828427</td>\n",
       "      <td>2980.957987</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>2.236068</td>\n",
       "      <td>148.413159</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       sqrt          exp\n",
       "A  2.000000    54.598150\n",
       "B  1.414214     7.389056\n",
       "C  1.414214     7.389056\n",
       "D  3.000000  8103.083928\n",
       "E  2.828427  2980.957987\n",
       "F  1.414214     7.389056\n",
       "H  2.236068   148.413159\n",
       "I  2.449490   403.428793\n",
       "J  2.828427  2980.957987\n",
       "K  2.236068   148.413159"
      ]
     },
     "execution_count": 180,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1、⼀列执⾏多项计算 ----apply也可以实现该操作\n",
    "df['Python'].transform([np.sqrt,np.exp]) # Series处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 181,
   "id": "committed-parking",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sqrt</th>\n",
       "      <th>exp</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>2.000000</td>\n",
       "      <td>54.598150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>1.414214</td>\n",
       "      <td>7.389056</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>1.414214</td>\n",
       "      <td>7.389056</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>3.000000</td>\n",
       "      <td>8103.083928</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>2.828427</td>\n",
       "      <td>2980.957987</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>1.414214</td>\n",
       "      <td>7.389056</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>2.236068</td>\n",
       "      <td>148.413159</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>2.449490</td>\n",
       "      <td>403.428793</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>2.828427</td>\n",
       "      <td>2980.957987</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>2.236068</td>\n",
       "      <td>148.413159</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       sqrt          exp\n",
       "A  2.000000    54.598150\n",
       "B  1.414214     7.389056\n",
       "C  1.414214     7.389056\n",
       "D  3.000000  8103.083928\n",
       "E  2.828427  2980.957987\n",
       "F  1.414214     7.389056\n",
       "H  2.236068   148.413159\n",
       "I  2.449490   403.428793\n",
       "J  2.828427  2980.957987\n",
       "K  2.236068   148.413159"
      ]
     },
     "execution_count": 181,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['Python'].apply([np.sqrt,np.exp]) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 182,
   "id": "trying-switch",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>40</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>20</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>20</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>90</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>80</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>20</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>50</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>60</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>80</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>50</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A      40           9      0\n",
       "B      20           9      0\n",
       "C      20           9      0\n",
       "D      90           9      0\n",
       "E      80           9      0\n",
       "F      20           9      0\n",
       "H      50           9      0\n",
       "I      60           9      0\n",
       "J      80           9      0\n",
       "K      50           9      0"
      ]
     },
     "execution_count": 182,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2、多列执⾏不同计算-------apply也可以\n",
    "def convert(x):\n",
    " if x.mean() > 5:\n",
    "     x *= 10\n",
    " else:\n",
    "     x *= -10\n",
    " return x\n",
    "df.transform({'Python':convert,'Tensorflow':np.max,'Keras':np.min}) # DataFrame处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 183,
   "id": "optical-transsexual",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>400</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>200</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>200</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>900</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>800</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>200</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>500</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>600</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>800</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>500</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A     400           9      0\n",
       "B     200           9      0\n",
       "C     200           9      0\n",
       "D     900           9      0\n",
       "E     800           9      0\n",
       "F     200           9      0\n",
       "H     500           9      0\n",
       "I     600           9      0\n",
       "J     800           9      0\n",
       "K     500           9      0"
      ]
     },
     "execution_count": 183,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.apply({'Python':convert,'Tensorflow':np.max,'Keras':np.min}) # DataFrame处理"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "coated-leadership",
   "metadata": {},
   "source": [
    "### 重排随机抽样哑变量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 184,
   "id": "charitable-gates",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>400</td>\n",
       "      <td>2</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>200</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>200</td>\n",
       "      <td>1</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>900</td>\n",
       "      <td>9</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>800</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>200</td>\n",
       "      <td>7</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>500</td>\n",
       "      <td>6</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>600</td>\n",
       "      <td>3</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>800</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>500</td>\n",
       "      <td>8</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A     400           2      6\n",
       "B     200           9      6\n",
       "C     200           1      9\n",
       "D     900           9      3\n",
       "E     800           3      0\n",
       "F     200           7      9\n",
       "H     500           6      5\n",
       "I     600           3      7\n",
       "J     800           0      5\n",
       "K     500           8      3"
      ]
     },
     "execution_count": 184,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 186,
   "id": "alien-flush",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([8, 0, 5, 3, 9, 1, 4, 7, 2, 6])"
      ]
     },
     "execution_count": 186,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#返回打乱顺序的索引\n",
    "ran = np.random.permutation(10) # 随机重排\n",
    "ran"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 188,
   "id": "chinese-possession",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>800</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>400</td>\n",
       "      <td>2</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>200</td>\n",
       "      <td>7</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>900</td>\n",
       "      <td>9</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>500</td>\n",
       "      <td>8</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>200</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>800</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>600</td>\n",
       "      <td>3</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>200</td>\n",
       "      <td>1</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>500</td>\n",
       "      <td>6</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "J     800           0      5\n",
       "A     400           2      6\n",
       "F     200           7      9\n",
       "D     900           9      3\n",
       "K     500           8      3\n",
       "B     200           9      6\n",
       "E     800           3      0\n",
       "I     600           3      7\n",
       "C     200           1      9\n",
       "H     500           6      5"
      ]
     },
     "execution_count": 188,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.take(ran) # 重排DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 189,
   "id": "desperate-shaft",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>500</td>\n",
       "      <td>8</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>800</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>600</td>\n",
       "      <td>3</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>800</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>800</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>900</td>\n",
       "      <td>9</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>200</td>\n",
       "      <td>7</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>400</td>\n",
       "      <td>2</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>200</td>\n",
       "      <td>1</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>500</td>\n",
       "      <td>8</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>200</td>\n",
       "      <td>7</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>900</td>\n",
       "      <td>9</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>200</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>800</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>200</td>\n",
       "      <td>9</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "K     500           8      3\n",
       "E     800           3      0\n",
       "I     600           3      7\n",
       "E     800           3      0\n",
       "J     800           0      5\n",
       "D     900           9      3\n",
       "F     200           7      9\n",
       "A     400           2      6\n",
       "C     200           1      9\n",
       "K     500           8      3\n",
       "F     200           7      9\n",
       "D     900           9      3\n",
       "B     200           9      6\n",
       "E     800           3      0\n",
       "B     200           9      6"
      ]
     },
     "execution_count": 189,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#随机抽样，从大量数据中随机抽取数据\n",
    "df.take(np.random.randint(0,10,size = 15)) # 随机抽样"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 191,
   "id": "biblical-generator",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>key</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>b</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>b</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>a</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>c</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>a</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>b</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  key\n",
       "0   b\n",
       "1   b\n",
       "2   a\n",
       "3   c\n",
       "4   a\n",
       "5   b"
      ]
     },
     "execution_count": 191,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#哑变量--->  one-hot\n",
    "# 哑变量，独热编码，1表示有，0表示没有\n",
    "#str类型，经过哑变量变换可以使用数字表示\n",
    "df = pd.DataFrame({'key':['b','b','a','c','a','b']})\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 192,
   "id": "associate-gazette",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>a</th>\n",
       "      <th>b</th>\n",
       "      <th>c</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   a  b  c\n",
       "0  0  1  0\n",
       "1  0  1  0\n",
       "2  1  0  0\n",
       "3  0  0  1\n",
       "4  1  0  0\n",
       "5  0  1  0"
      ]
     },
     "execution_count": 192,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.get_dummies(df,prefix='',prefix_sep='')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "legendary-barbados",
   "metadata": {},
   "source": [
    "## 数据重塑"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 194,
   "id": "coordinated-breakdown",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>7</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>6</td>\n",
       "      <td>4</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>5</td>\n",
       "      <td>7</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>3</td>\n",
       "      <td>8</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A       7           3      2\n",
       "B       4           2      7\n",
       "C       4           2      0\n",
       "D       6           4      8\n",
       "E       3           4      3\n",
       "F       7           8      0\n",
       "H       5           7      5\n",
       "I       7           2      0\n",
       "J       4           5      6\n",
       "K       3           8      1"
      ]
     },
     "execution_count": 194,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,10,size = (10,3)),\n",
    " index = list('ABCDEFHIJK'),\n",
    " columns=['Python','Tensorflow','Keras'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 195,
   "id": "criminal-barbados",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "      <th>F</th>\n",
       "      <th>H</th>\n",
       "      <th>I</th>\n",
       "      <th>J</th>\n",
       "      <th>K</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Python</th>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>6</td>\n",
       "      <td>3</td>\n",
       "      <td>7</td>\n",
       "      <td>5</td>\n",
       "      <td>7</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>8</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>2</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            A  B  C  D  E  F  H  I  J  K\n",
       "Python      7  4  4  6  3  7  5  7  4  3\n",
       "Tensorflow  3  2  2  4  4  8  7  2  5  8\n",
       "Keras       2  7  0  8  3  0  5  0  6  1"
      ]
     },
     "execution_count": 195,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.T"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 197,
   "id": "productive-rental",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">A</th>\n",
       "      <th>期 中</th>\n",
       "      <td>73</td>\n",
       "      <td>62</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>期末</th>\n",
       "      <td>91</td>\n",
       "      <td>93</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">B</th>\n",
       "      <th>期 中</th>\n",
       "      <td>23</td>\n",
       "      <td>2</td>\n",
       "      <td>31</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>期末</th>\n",
       "      <td>11</td>\n",
       "      <td>34</td>\n",
       "      <td>58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">C</th>\n",
       "      <th>期 中</th>\n",
       "      <td>69</td>\n",
       "      <td>22</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>期末</th>\n",
       "      <td>29</td>\n",
       "      <td>18</td>\n",
       "      <td>49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">D</th>\n",
       "      <th>期 中</th>\n",
       "      <td>6</td>\n",
       "      <td>44</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>期末</th>\n",
       "      <td>81</td>\n",
       "      <td>23</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">E</th>\n",
       "      <th>期 中</th>\n",
       "      <td>5</td>\n",
       "      <td>88</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>期末</th>\n",
       "      <td>21</td>\n",
       "      <td>11</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">F</th>\n",
       "      <th>期 中</th>\n",
       "      <td>4</td>\n",
       "      <td>69</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>期末</th>\n",
       "      <td>70</td>\n",
       "      <td>70</td>\n",
       "      <td>69</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">H</th>\n",
       "      <th>期 中</th>\n",
       "      <td>37</td>\n",
       "      <td>72</td>\n",
       "      <td>41</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>期末</th>\n",
       "      <td>43</td>\n",
       "      <td>73</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">I</th>\n",
       "      <th>期 中</th>\n",
       "      <td>32</td>\n",
       "      <td>48</td>\n",
       "      <td>57</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>期末</th>\n",
       "      <td>35</td>\n",
       "      <td>43</td>\n",
       "      <td>97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">J</th>\n",
       "      <th>期 中</th>\n",
       "      <td>35</td>\n",
       "      <td>29</td>\n",
       "      <td>82</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>期末</th>\n",
       "      <td>45</td>\n",
       "      <td>83</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"2\" valign=\"top\">K</th>\n",
       "      <th>期 中</th>\n",
       "      <td>51</td>\n",
       "      <td>44</td>\n",
       "      <td>97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>期末</th>\n",
       "      <td>43</td>\n",
       "      <td>51</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       Python  Tensorflow  Keras\n",
       "A 期 中      73          62      2\n",
       "  期末       91          93     22\n",
       "B 期 中      23           2     31\n",
       "  期末       11          34     58\n",
       "C 期 中      69          22     35\n",
       "  期末       29          18     49\n",
       "D 期 中       6          44     54\n",
       "  期末       81          23     48\n",
       "E 期 中       5          88     48\n",
       "  期末       21          11      3\n",
       "F 期 中       4          69     75\n",
       "  期末       70          70     69\n",
       "H 期 中      37          72     41\n",
       "  期末       43          73     80\n",
       "I 期 中      32          48     57\n",
       "  期末       35          43     97\n",
       "J 期 中      35          29     82\n",
       "  期末       45          83      6\n",
       "K 期 中      51          44     97\n",
       "  期末       43          51     28"
      ]
     },
     "execution_count": 197,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#多层索引\n",
    "df2 = pd.DataFrame(data = np.random.randint(0,100,size = (20,3)),\n",
    " index = pd.MultiIndex.from_product([list('ABCDEFHIJK'),['期 中','期末']]),\n",
    " columns=['Python','Tensorflow','Keras'])\n",
    "df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 199,
   "id": "likely-linux",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th colspan=\"2\" halign=\"left\">Python</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Tensorflow</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Keras</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>期 中</th>\n",
       "      <th>期末</th>\n",
       "      <th>期 中</th>\n",
       "      <th>期末</th>\n",
       "      <th>期 中</th>\n",
       "      <th>期末</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>73</td>\n",
       "      <td>91</td>\n",
       "      <td>62</td>\n",
       "      <td>93</td>\n",
       "      <td>2</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>23</td>\n",
       "      <td>11</td>\n",
       "      <td>2</td>\n",
       "      <td>34</td>\n",
       "      <td>31</td>\n",
       "      <td>58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>69</td>\n",
       "      <td>29</td>\n",
       "      <td>22</td>\n",
       "      <td>18</td>\n",
       "      <td>35</td>\n",
       "      <td>49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>6</td>\n",
       "      <td>81</td>\n",
       "      <td>44</td>\n",
       "      <td>23</td>\n",
       "      <td>54</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>5</td>\n",
       "      <td>21</td>\n",
       "      <td>88</td>\n",
       "      <td>11</td>\n",
       "      <td>48</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>4</td>\n",
       "      <td>70</td>\n",
       "      <td>69</td>\n",
       "      <td>70</td>\n",
       "      <td>75</td>\n",
       "      <td>69</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>37</td>\n",
       "      <td>43</td>\n",
       "      <td>72</td>\n",
       "      <td>73</td>\n",
       "      <td>41</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>32</td>\n",
       "      <td>35</td>\n",
       "      <td>48</td>\n",
       "      <td>43</td>\n",
       "      <td>57</td>\n",
       "      <td>97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>35</td>\n",
       "      <td>45</td>\n",
       "      <td>29</td>\n",
       "      <td>83</td>\n",
       "      <td>82</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>51</td>\n",
       "      <td>43</td>\n",
       "      <td>44</td>\n",
       "      <td>51</td>\n",
       "      <td>97</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Python     Tensorflow     Keras    \n",
       "     期 中  期末        期 中  期末   期 中  期末\n",
       "A     73  91         62  93     2  22\n",
       "B     23  11          2  34    31  58\n",
       "C     69  29         22  18    35  49\n",
       "D      6  81         44  23    54  48\n",
       "E      5  21         88  11    48   3\n",
       "F      4  70         69  70    75  69\n",
       "H     37  43         72  73    41  80\n",
       "I     32  35         48  43    57  97\n",
       "J     35  45         29  83    82   6\n",
       "K     51  43         44  51    97  28"
      ]
     },
     "execution_count": 199,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.unstack()  #将行索引变成列索引，level参数默认是-1，表示最后一层（期中期末）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 203,
   "id": "subsequent-defeat",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th colspan=\"2\" halign=\"left\">Python</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Tensorflow</th>\n",
       "      <th colspan=\"2\" halign=\"left\">Keras</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>期 中</th>\n",
       "      <th>期末</th>\n",
       "      <th>期 中</th>\n",
       "      <th>期末</th>\n",
       "      <th>期 中</th>\n",
       "      <th>期末</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>73</td>\n",
       "      <td>91</td>\n",
       "      <td>62</td>\n",
       "      <td>93</td>\n",
       "      <td>2</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>23</td>\n",
       "      <td>11</td>\n",
       "      <td>2</td>\n",
       "      <td>34</td>\n",
       "      <td>31</td>\n",
       "      <td>58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>69</td>\n",
       "      <td>29</td>\n",
       "      <td>22</td>\n",
       "      <td>18</td>\n",
       "      <td>35</td>\n",
       "      <td>49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>6</td>\n",
       "      <td>81</td>\n",
       "      <td>44</td>\n",
       "      <td>23</td>\n",
       "      <td>54</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>5</td>\n",
       "      <td>21</td>\n",
       "      <td>88</td>\n",
       "      <td>11</td>\n",
       "      <td>48</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>4</td>\n",
       "      <td>70</td>\n",
       "      <td>69</td>\n",
       "      <td>70</td>\n",
       "      <td>75</td>\n",
       "      <td>69</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>37</td>\n",
       "      <td>43</td>\n",
       "      <td>72</td>\n",
       "      <td>73</td>\n",
       "      <td>41</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>32</td>\n",
       "      <td>35</td>\n",
       "      <td>48</td>\n",
       "      <td>43</td>\n",
       "      <td>57</td>\n",
       "      <td>97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>35</td>\n",
       "      <td>45</td>\n",
       "      <td>29</td>\n",
       "      <td>83</td>\n",
       "      <td>82</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>51</td>\n",
       "      <td>43</td>\n",
       "      <td>44</td>\n",
       "      <td>51</td>\n",
       "      <td>97</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Python     Tensorflow     Keras    \n",
       "     期 中  期末        期 中  期末   期 中  期末\n",
       "A     73  91         62  93     2  22\n",
       "B     23  11          2  34    31  58\n",
       "C     69  29         22  18    35  49\n",
       "D      6  81         44  23    54  48\n",
       "E      5  21         88  11    48   3\n",
       "F      4  70         69  70    75  69\n",
       "H     37  43         72  73    41  80\n",
       "I     32  35         48  43    57  97\n",
       "J     35  45         29  83    82   6\n",
       "K     51  43         44  51    97  28"
      ]
     },
     "execution_count": 203,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.unstack(level = 1)  #正着数？倒着数？"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 202,
   "id": "increased-chemical",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th colspan=\"10\" halign=\"left\">Python</th>\n",
       "      <th>...</th>\n",
       "      <th colspan=\"10\" halign=\"left\">Keras</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "      <th>F</th>\n",
       "      <th>H</th>\n",
       "      <th>I</th>\n",
       "      <th>J</th>\n",
       "      <th>K</th>\n",
       "      <th>...</th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "      <th>F</th>\n",
       "      <th>H</th>\n",
       "      <th>I</th>\n",
       "      <th>J</th>\n",
       "      <th>K</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>期 中</th>\n",
       "      <td>73</td>\n",
       "      <td>23</td>\n",
       "      <td>69</td>\n",
       "      <td>6</td>\n",
       "      <td>5</td>\n",
       "      <td>4</td>\n",
       "      <td>37</td>\n",
       "      <td>32</td>\n",
       "      <td>35</td>\n",
       "      <td>51</td>\n",
       "      <td>...</td>\n",
       "      <td>2</td>\n",
       "      <td>31</td>\n",
       "      <td>35</td>\n",
       "      <td>54</td>\n",
       "      <td>48</td>\n",
       "      <td>75</td>\n",
       "      <td>41</td>\n",
       "      <td>57</td>\n",
       "      <td>82</td>\n",
       "      <td>97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>期末</th>\n",
       "      <td>91</td>\n",
       "      <td>11</td>\n",
       "      <td>29</td>\n",
       "      <td>81</td>\n",
       "      <td>21</td>\n",
       "      <td>70</td>\n",
       "      <td>43</td>\n",
       "      <td>35</td>\n",
       "      <td>45</td>\n",
       "      <td>43</td>\n",
       "      <td>...</td>\n",
       "      <td>22</td>\n",
       "      <td>58</td>\n",
       "      <td>49</td>\n",
       "      <td>48</td>\n",
       "      <td>3</td>\n",
       "      <td>69</td>\n",
       "      <td>80</td>\n",
       "      <td>97</td>\n",
       "      <td>6</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>2 rows × 30 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    Python                                      ... Keras                      \\\n",
       "         A   B   C   D   E   F   H   I   J   K  ...     A   B   C   D   E   F   \n",
       "期 中     73  23  69   6   5   4  37  32  35  51  ...     2  31  35  54  48  75   \n",
       "期末      91  11  29  81  21  70  43  35  45  43  ...    22  58  49  48   3  69   \n",
       "\n",
       "                     \n",
       "      H   I   J   K  \n",
       "期 中  41  57  82  97  \n",
       "期末   80  97   6  28  \n",
       "\n",
       "[2 rows x 30 columns]"
      ]
     },
     "execution_count": 202,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.unstack(0)  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 204,
   "id": "bibliographic-introduction",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A  期 中  Python        73\n",
       "        Tensorflow    62\n",
       "        Keras          2\n",
       "   期末   Python        91\n",
       "        Tensorflow    93\n",
       "        Keras         22\n",
       "B  期 中  Python        23\n",
       "        Tensorflow     2\n",
       "        Keras         31\n",
       "   期末   Python        11\n",
       "        Tensorflow    34\n",
       "        Keras         58\n",
       "C  期 中  Python        69\n",
       "        Tensorflow    22\n",
       "        Keras         35\n",
       "   期末   Python        29\n",
       "        Tensorflow    18\n",
       "        Keras         49\n",
       "D  期 中  Python         6\n",
       "        Tensorflow    44\n",
       "        Keras         54\n",
       "   期末   Python        81\n",
       "        Tensorflow    23\n",
       "        Keras         48\n",
       "E  期 中  Python         5\n",
       "        Tensorflow    88\n",
       "        Keras         48\n",
       "   期末   Python        21\n",
       "        Tensorflow    11\n",
       "        Keras          3\n",
       "F  期 中  Python         4\n",
       "        Tensorflow    69\n",
       "        Keras         75\n",
       "   期末   Python        70\n",
       "        Tensorflow    70\n",
       "        Keras         69\n",
       "H  期 中  Python        37\n",
       "        Tensorflow    72\n",
       "        Keras         41\n",
       "   期末   Python        43\n",
       "        Tensorflow    73\n",
       "        Keras         80\n",
       "I  期 中  Python        32\n",
       "        Tensorflow    48\n",
       "        Keras         57\n",
       "   期末   Python        35\n",
       "        Tensorflow    43\n",
       "        Keras         97\n",
       "J  期 中  Python        35\n",
       "        Tensorflow    29\n",
       "        Keras         82\n",
       "   期末   Python        45\n",
       "        Tensorflow    83\n",
       "        Keras          6\n",
       "K  期 中  Python        51\n",
       "        Tensorflow    44\n",
       "        Keras         97\n",
       "   期末   Python        43\n",
       "        Tensorflow    51\n",
       "        Keras         28\n",
       "dtype: int32"
      ]
     },
     "execution_count": 204,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.stack() # 列旋转成⾏"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 205,
   "id": "premier-latest",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>期 中</th>\n",
       "      <th>期末</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">A</th>\n",
       "      <th>Python</th>\n",
       "      <td>73</td>\n",
       "      <td>91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>62</td>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>2</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">B</th>\n",
       "      <th>Python</th>\n",
       "      <td>23</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>2</td>\n",
       "      <td>34</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>31</td>\n",
       "      <td>58</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">C</th>\n",
       "      <th>Python</th>\n",
       "      <td>69</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>22</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>35</td>\n",
       "      <td>49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">D</th>\n",
       "      <th>Python</th>\n",
       "      <td>6</td>\n",
       "      <td>81</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>44</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>54</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">E</th>\n",
       "      <th>Python</th>\n",
       "      <td>5</td>\n",
       "      <td>21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>88</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>48</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">F</th>\n",
       "      <th>Python</th>\n",
       "      <td>4</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>69</td>\n",
       "      <td>70</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>75</td>\n",
       "      <td>69</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">H</th>\n",
       "      <th>Python</th>\n",
       "      <td>37</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>72</td>\n",
       "      <td>73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>41</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">I</th>\n",
       "      <th>Python</th>\n",
       "      <td>32</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>48</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>57</td>\n",
       "      <td>97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">J</th>\n",
       "      <th>Python</th>\n",
       "      <td>35</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>29</td>\n",
       "      <td>83</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>82</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"3\" valign=\"top\">K</th>\n",
       "      <th>Python</th>\n",
       "      <td>51</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>44</td>\n",
       "      <td>51</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>97</td>\n",
       "      <td>28</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              期 中  期末\n",
       "A Python       73  91\n",
       "  Tensorflow   62  93\n",
       "  Keras         2  22\n",
       "B Python       23  11\n",
       "  Tensorflow    2  34\n",
       "  Keras        31  58\n",
       "C Python       69  29\n",
       "  Tensorflow   22  18\n",
       "  Keras        35  49\n",
       "D Python        6  81\n",
       "  Tensorflow   44  23\n",
       "  Keras        54  48\n",
       "E Python        5  21\n",
       "  Tensorflow   88  11\n",
       "  Keras        48   3\n",
       "F Python        4  70\n",
       "  Tensorflow   69  70\n",
       "  Keras        75  69\n",
       "H Python       37  43\n",
       "  Tensorflow   72  73\n",
       "  Keras        41  80\n",
       "I Python       32  35\n",
       "  Tensorflow   48  43\n",
       "  Keras        57  97\n",
       "J Python       35  45\n",
       "  Tensorflow   29  83\n",
       "  Keras        82   6\n",
       "K Python       51  43\n",
       "  Tensorflow   44  51\n",
       "  Keras        97  28"
      ]
     },
     "execution_count": 205,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.stack().unstack(level = 1) # ⾏列互换"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 206,
   "id": "pediatric-priority",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python        40.20\n",
       "Tensorflow    48.95\n",
       "Keras         49.10\n",
       "dtype: float64"
      ]
     },
     "execution_count": 206,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.mean()#默认计算列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 207,
   "id": "fundamental-florist",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>期 中</th>\n",
       "      <td>33.5</td>\n",
       "      <td>48.0</td>\n",
       "      <td>52.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>期末</th>\n",
       "      <td>46.9</td>\n",
       "      <td>49.9</td>\n",
       "      <td>46.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     Python  Tensorflow  Keras\n",
       "期 中    33.5        48.0   52.2\n",
       "期末     46.9        49.9   46.0"
      ]
     },
     "execution_count": 207,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.mean(level = 1) #计算期中期末所有学生平均分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 208,
   "id": "material-healthcare",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>82.0</td>\n",
       "      <td>77.5</td>\n",
       "      <td>12.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>17.0</td>\n",
       "      <td>18.0</td>\n",
       "      <td>44.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>49.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>42.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>43.5</td>\n",
       "      <td>33.5</td>\n",
       "      <td>51.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>13.0</td>\n",
       "      <td>49.5</td>\n",
       "      <td>25.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>37.0</td>\n",
       "      <td>69.5</td>\n",
       "      <td>72.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>40.0</td>\n",
       "      <td>72.5</td>\n",
       "      <td>60.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>33.5</td>\n",
       "      <td>45.5</td>\n",
       "      <td>77.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>40.0</td>\n",
       "      <td>56.0</td>\n",
       "      <td>44.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>47.0</td>\n",
       "      <td>47.5</td>\n",
       "      <td>62.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A    82.0        77.5   12.0\n",
       "B    17.0        18.0   44.5\n",
       "C    49.0        20.0   42.0\n",
       "D    43.5        33.5   51.0\n",
       "E    13.0        49.5   25.5\n",
       "F    37.0        69.5   72.0\n",
       "H    40.0        72.5   60.5\n",
       "I    33.5        45.5   77.0\n",
       "J    40.0        56.0   44.0\n",
       "K    47.0        47.5   62.5"
      ]
     },
     "execution_count": 208,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2.mean(level = 0)#计算每位学生期中和期末平均分"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "adolescent-kelly",
   "metadata": {},
   "source": [
    "## 数学和统计方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "authorized-ordering",
   "metadata": {},
   "source": [
    "### 简单统计指标"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 209,
   "id": "unique-saturn",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>38</td>\n",
       "      <td>4</td>\n",
       "      <td>32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>22</td>\n",
       "      <td>32</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>27</td>\n",
       "      <td>7</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>25</td>\n",
       "      <td>82</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>79</td>\n",
       "      <td>53</td>\n",
       "      <td>97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>37</td>\n",
       "      <td>4</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>49</td>\n",
       "      <td>7</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>52</td>\n",
       "      <td>11</td>\n",
       "      <td>36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>79</td>\n",
       "      <td>71</td>\n",
       "      <td>47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>95</td>\n",
       "      <td>95</td>\n",
       "      <td>65</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>43</td>\n",
       "      <td>25</td>\n",
       "      <td>25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>89</td>\n",
       "      <td>81</td>\n",
       "      <td>21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>8</td>\n",
       "      <td>18</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>5</td>\n",
       "      <td>52</td>\n",
       "      <td>74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>63</td>\n",
       "      <td>6</td>\n",
       "      <td>47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>31</td>\n",
       "      <td>29</td>\n",
       "      <td>29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>63</td>\n",
       "      <td>13</td>\n",
       "      <td>59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>80</td>\n",
       "      <td>98</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>10</td>\n",
       "      <td>84</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>U</th>\n",
       "      <td>4</td>\n",
       "      <td>92</td>\n",
       "      <td>92</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A      38           4     32\n",
       "B      22          32     23\n",
       "C      27           7     90\n",
       "D      25          82     45\n",
       "E      79          53     97\n",
       "F      37           4     99\n",
       "H      49           7     76\n",
       "I      52          11     36\n",
       "J      79          71     47\n",
       "K      95          95     65\n",
       "L      43          25     25\n",
       "M      89          81     21\n",
       "N       8          18     94\n",
       "O       5          52     74\n",
       "P      63           6     47\n",
       "Q      31          29     29\n",
       "R      63          13     59\n",
       "S      80          98     20\n",
       "T      10          84     19\n",
       "U       4          92     92"
      ]
     },
     "execution_count": 209,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,100,size = (20,3)),\n",
    " index = list('ABCDEFHIJKLMNOPQRSTU'),\n",
    " columns=['Python','Tensorflow','Keras'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 212,
   "id": "renewable-salem",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>38</td>\n",
       "      <td>4</td>\n",
       "      <td>32.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>22</td>\n",
       "      <td>32</td>\n",
       "      <td>23.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>27</td>\n",
       "      <td>7</td>\n",
       "      <td>90.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>25</td>\n",
       "      <td>82</td>\n",
       "      <td>45.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>79</td>\n",
       "      <td>53</td>\n",
       "      <td>97.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>37</td>\n",
       "      <td>4</td>\n",
       "      <td>99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>49</td>\n",
       "      <td>7</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>52</td>\n",
       "      <td>11</td>\n",
       "      <td>36.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>79</td>\n",
       "      <td>71</td>\n",
       "      <td>47.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>95</td>\n",
       "      <td>95</td>\n",
       "      <td>65.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>43</td>\n",
       "      <td>25</td>\n",
       "      <td>25.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>89</td>\n",
       "      <td>81</td>\n",
       "      <td>21.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>8</td>\n",
       "      <td>18</td>\n",
       "      <td>94.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>5</td>\n",
       "      <td>52</td>\n",
       "      <td>74.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>63</td>\n",
       "      <td>6</td>\n",
       "      <td>47.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>31</td>\n",
       "      <td>29</td>\n",
       "      <td>29.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>63</td>\n",
       "      <td>13</td>\n",
       "      <td>59.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>80</td>\n",
       "      <td>98</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>10</td>\n",
       "      <td>84</td>\n",
       "      <td>19.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>U</th>\n",
       "      <td>4</td>\n",
       "      <td>92</td>\n",
       "      <td>92.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A      38           4   32.0\n",
       "B      22          32   23.0\n",
       "C      27           7   90.0\n",
       "D      25          82   45.0\n",
       "E      79          53   97.0\n",
       "F      37           4   99.0\n",
       "H      49           7    NaN\n",
       "I      52          11   36.0\n",
       "J      79          71   47.0\n",
       "K      95          95   65.0\n",
       "L      43          25   25.0\n",
       "M      89          81   21.0\n",
       "N       8          18   94.0\n",
       "O       5          52   74.0\n",
       "P      63           6   47.0\n",
       "Q      31          29   29.0\n",
       "R      63          13   59.0\n",
       "S      80          98   20.0\n",
       "T      10          84   19.0\n",
       "U       4          92   92.0"
      ]
     },
     "execution_count": 212,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[6,2]= np.NAN\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 213,
   "id": "proved-fireplace",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python        20\n",
       "Tensorflow    20\n",
       "Keras         19\n",
       "dtype: int64"
      ]
     },
     "execution_count": 213,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.count()  #统计非空数据的数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 214,
   "id": "motivated-integrity",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python        44.950000\n",
       "Tensorflow    43.200000\n",
       "Keras         53.368421\n",
       "dtype: float64"
      ]
     },
     "execution_count": 214,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 216,
   "id": "according-adobe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(Python        40.5\n",
       " Tensorflow    30.5\n",
       " Keras         47.0\n",
       " dtype: float64,\n",
       " Python         4.0\n",
       " Tensorflow     4.0\n",
       " Keras         19.0\n",
       " dtype: float64)"
      ]
     },
     "execution_count": 216,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.median(),df.min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 217,
   "id": "genuine-prediction",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([38, 22, 27, 25, 79, 37, 49, 52, 95, 43, 89,  8,  5, 63, 31, 80, 10,\n",
       "        4], dtype=int64)"
      ]
     },
     "execution_count": 217,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['Python'].unique()  #去重"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 218,
   "id": "pointed-consent",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4     2\n",
       "7     2\n",
       "95    1\n",
       "29    1\n",
       "98    1\n",
       "18    1\n",
       "6     1\n",
       "84    1\n",
       "11    1\n",
       "13    1\n",
       "81    1\n",
       "82    1\n",
       "52    1\n",
       "53    1\n",
       "71    1\n",
       "25    1\n",
       "92    1\n",
       "32    1\n",
       "Name: Tensorflow, dtype: int64"
      ]
     },
     "execution_count": 218,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['Tensorflow'].value_counts() #统计每个值出现的频次"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 219,
   "id": "accomplished-mission",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0.00</th>\n",
       "      <td>4.00</td>\n",
       "      <td>4.00</td>\n",
       "      <td>19.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.25</th>\n",
       "      <td>24.25</td>\n",
       "      <td>10.00</td>\n",
       "      <td>27.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.50</th>\n",
       "      <td>40.50</td>\n",
       "      <td>30.50</td>\n",
       "      <td>47.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0.75</th>\n",
       "      <td>67.00</td>\n",
       "      <td>81.25</td>\n",
       "      <td>82.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1.00</th>\n",
       "      <td>95.00</td>\n",
       "      <td>98.00</td>\n",
       "      <td>99.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      Python  Tensorflow  Keras\n",
       "0.00    4.00        4.00   19.0\n",
       "0.25   24.25       10.00   27.0\n",
       "0.50   40.50       30.50   47.0\n",
       "0.75   67.00       81.25   82.0\n",
       "1.00   95.00       98.00   99.0"
      ]
     },
     "execution_count": 219,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.quantile(q = [0,0.25,0.5,0.75,1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 220,
   "id": "lyric-track",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>20.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>19.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>45.0</td>\n",
       "      <td>43.2</td>\n",
       "      <td>53.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>29.1</td>\n",
       "      <td>35.5</td>\n",
       "      <td>29.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>19.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>24.2</td>\n",
       "      <td>10.0</td>\n",
       "      <td>27.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>40.5</td>\n",
       "      <td>30.5</td>\n",
       "      <td>47.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>67.0</td>\n",
       "      <td>81.2</td>\n",
       "      <td>82.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>95.0</td>\n",
       "      <td>98.0</td>\n",
       "      <td>99.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       Python  Tensorflow  Keras\n",
       "count    20.0        20.0   19.0\n",
       "mean     45.0        43.2   53.4\n",
       "std      29.1        35.5   29.5\n",
       "min       4.0         4.0   19.0\n",
       "25%      24.2        10.0   27.0\n",
       "50%      40.5        30.5   47.0\n",
       "75%      67.0        81.2   82.0\n",
       "max      95.0        98.0   99.0"
      ]
     },
     "execution_count": 220,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.describe().round(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "surgical-works",
   "metadata": {},
   "source": [
    "### 索引标签、位置获取"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 221,
   "id": "everyday-builder",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "d:\\python3.7.3\\lib\\site-packages\\ipykernel_launcher.py:1: FutureWarning: \n",
      "The current behaviour of 'Series.argmax' is deprecated, use 'idxmax'\n",
      "instead.\n",
      "The behavior of 'argmax' will be corrected to return the positional\n",
      "maximum in the future. For now, use 'series.values.argmax' or\n",
      "'np.argmax(np.array(values))' to get the position of the maximum\n",
      "row.\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'K'"
      ]
     },
     "execution_count": 221,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['Python'].argmax()  #返回最大值索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 222,
   "id": "ranging-calculation",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python        K\n",
       "Tensorflow    S\n",
       "Keras         F\n",
       "dtype: object"
      ]
     },
     "execution_count": 222,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.idxmax()#返回最大值的标签"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "material-integration",
   "metadata": {},
   "source": [
    "### 更多统计指标"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 223,
   "id": "promotional-wesley",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>38.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>32.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>60.0</td>\n",
       "      <td>36.0</td>\n",
       "      <td>55.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>87.0</td>\n",
       "      <td>43.0</td>\n",
       "      <td>145.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>112.0</td>\n",
       "      <td>125.0</td>\n",
       "      <td>190.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>191.0</td>\n",
       "      <td>178.0</td>\n",
       "      <td>287.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>228.0</td>\n",
       "      <td>182.0</td>\n",
       "      <td>386.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>277.0</td>\n",
       "      <td>189.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>329.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>422.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>408.0</td>\n",
       "      <td>271.0</td>\n",
       "      <td>469.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>503.0</td>\n",
       "      <td>366.0</td>\n",
       "      <td>534.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>546.0</td>\n",
       "      <td>391.0</td>\n",
       "      <td>559.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>635.0</td>\n",
       "      <td>472.0</td>\n",
       "      <td>580.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>643.0</td>\n",
       "      <td>490.0</td>\n",
       "      <td>674.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>648.0</td>\n",
       "      <td>542.0</td>\n",
       "      <td>748.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>711.0</td>\n",
       "      <td>548.0</td>\n",
       "      <td>795.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>742.0</td>\n",
       "      <td>577.0</td>\n",
       "      <td>824.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>805.0</td>\n",
       "      <td>590.0</td>\n",
       "      <td>883.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>885.0</td>\n",
       "      <td>688.0</td>\n",
       "      <td>903.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>895.0</td>\n",
       "      <td>772.0</td>\n",
       "      <td>922.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>U</th>\n",
       "      <td>899.0</td>\n",
       "      <td>864.0</td>\n",
       "      <td>1014.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow   Keras\n",
       "A    38.0         4.0    32.0\n",
       "B    60.0        36.0    55.0\n",
       "C    87.0        43.0   145.0\n",
       "D   112.0       125.0   190.0\n",
       "E   191.0       178.0   287.0\n",
       "F   228.0       182.0   386.0\n",
       "H   277.0       189.0     NaN\n",
       "I   329.0       200.0   422.0\n",
       "J   408.0       271.0   469.0\n",
       "K   503.0       366.0   534.0\n",
       "L   546.0       391.0   559.0\n",
       "M   635.0       472.0   580.0\n",
       "N   643.0       490.0   674.0\n",
       "O   648.0       542.0   748.0\n",
       "P   711.0       548.0   795.0\n",
       "Q   742.0       577.0   824.0\n",
       "R   805.0       590.0   883.0\n",
       "S   885.0       688.0   903.0\n",
       "T   895.0       772.0   922.0\n",
       "U   899.0       864.0  1014.0"
      ]
     },
     "execution_count": 223,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.cumsum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 224,
   "id": "illegal-warrior",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>3.800000e+01</td>\n",
       "      <td>4.000000e+00</td>\n",
       "      <td>3.200000e+01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>8.360000e+02</td>\n",
       "      <td>1.280000e+02</td>\n",
       "      <td>7.360000e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>2.257200e+04</td>\n",
       "      <td>8.960000e+02</td>\n",
       "      <td>6.624000e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>5.643000e+05</td>\n",
       "      <td>7.347200e+04</td>\n",
       "      <td>2.980800e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>4.457970e+07</td>\n",
       "      <td>3.894016e+06</td>\n",
       "      <td>2.891376e+08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>1.649449e+09</td>\n",
       "      <td>1.557606e+07</td>\n",
       "      <td>2.862462e+10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>8.082300e+10</td>\n",
       "      <td>1.090324e+08</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>4.202796e+12</td>\n",
       "      <td>1.199357e+09</td>\n",
       "      <td>1.030486e+12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>3.320209e+14</td>\n",
       "      <td>8.515434e+10</td>\n",
       "      <td>4.843286e+13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>3.154198e+16</td>\n",
       "      <td>8.089662e+12</td>\n",
       "      <td>3.148136e+15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>1.356305e+18</td>\n",
       "      <td>2.022416e+14</td>\n",
       "      <td>7.870340e+16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>1.207112e+20</td>\n",
       "      <td>1.638157e+16</td>\n",
       "      <td>1.652771e+18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>9.656893e+20</td>\n",
       "      <td>2.948682e+17</td>\n",
       "      <td>1.553605e+20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>4.828447e+21</td>\n",
       "      <td>1.533315e+19</td>\n",
       "      <td>1.149668e+22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>3.041921e+23</td>\n",
       "      <td>9.199888e+19</td>\n",
       "      <td>5.403439e+23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>9.429956e+24</td>\n",
       "      <td>2.667967e+21</td>\n",
       "      <td>1.566997e+25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>5.940873e+26</td>\n",
       "      <td>3.468358e+22</td>\n",
       "      <td>9.245283e+26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>4.752698e+28</td>\n",
       "      <td>3.398991e+24</td>\n",
       "      <td>1.849057e+28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>4.752698e+29</td>\n",
       "      <td>2.855152e+26</td>\n",
       "      <td>3.513208e+29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>U</th>\n",
       "      <td>1.901079e+30</td>\n",
       "      <td>2.626740e+28</td>\n",
       "      <td>3.232151e+31</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         Python    Tensorflow         Keras\n",
       "A  3.800000e+01  4.000000e+00  3.200000e+01\n",
       "B  8.360000e+02  1.280000e+02  7.360000e+02\n",
       "C  2.257200e+04  8.960000e+02  6.624000e+04\n",
       "D  5.643000e+05  7.347200e+04  2.980800e+06\n",
       "E  4.457970e+07  3.894016e+06  2.891376e+08\n",
       "F  1.649449e+09  1.557606e+07  2.862462e+10\n",
       "H  8.082300e+10  1.090324e+08           NaN\n",
       "I  4.202796e+12  1.199357e+09  1.030486e+12\n",
       "J  3.320209e+14  8.515434e+10  4.843286e+13\n",
       "K  3.154198e+16  8.089662e+12  3.148136e+15\n",
       "L  1.356305e+18  2.022416e+14  7.870340e+16\n",
       "M  1.207112e+20  1.638157e+16  1.652771e+18\n",
       "N  9.656893e+20  2.948682e+17  1.553605e+20\n",
       "O  4.828447e+21  1.533315e+19  1.149668e+22\n",
       "P  3.041921e+23  9.199888e+19  5.403439e+23\n",
       "Q  9.429956e+24  2.667967e+21  1.566997e+25\n",
       "R  5.940873e+26  3.468358e+22  9.245283e+26\n",
       "S  4.752698e+28  3.398991e+24  1.849057e+28\n",
       "T  4.752698e+29  2.855152e+26  3.513208e+29\n",
       "U  1.901079e+30  2.626740e+28  3.232151e+31"
      ]
     },
     "execution_count": 224,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.cumprod()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 225,
   "id": "ordinary-google",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>38.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>32.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>22.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>23.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>22.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>23.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>22.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>23.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>22.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>23.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>22.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>23.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>22.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>22.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>23.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>22.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>23.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>22.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>23.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>22.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>23.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>22.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>21.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>8.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>21.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>5.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>21.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>5.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>21.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>5.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>21.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>5.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>21.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>5.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>5.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>19.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>U</th>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>19.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A    38.0         4.0   32.0\n",
       "B    22.0         4.0   23.0\n",
       "C    22.0         4.0   23.0\n",
       "D    22.0         4.0   23.0\n",
       "E    22.0         4.0   23.0\n",
       "F    22.0         4.0   23.0\n",
       "H    22.0         4.0    NaN\n",
       "I    22.0         4.0   23.0\n",
       "J    22.0         4.0   23.0\n",
       "K    22.0         4.0   23.0\n",
       "L    22.0         4.0   23.0\n",
       "M    22.0         4.0   21.0\n",
       "N     8.0         4.0   21.0\n",
       "O     5.0         4.0   21.0\n",
       "P     5.0         4.0   21.0\n",
       "Q     5.0         4.0   21.0\n",
       "R     5.0         4.0   21.0\n",
       "S     5.0         4.0   20.0\n",
       "T     5.0         4.0   19.0\n",
       "U     4.0         4.0   19.0"
      ]
     },
     "execution_count": 225,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.cummin()  #-----累计最小值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 226,
   "id": "false-danish",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python        29.133947\n",
       "Tensorflow    35.491437\n",
       "Keras         29.473548\n",
       "dtype: float64"
      ]
     },
     "execution_count": 226,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.std()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 227,
   "id": "parliamentary-wyoming",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>-16.0</td>\n",
       "      <td>28.0</td>\n",
       "      <td>-9.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>5.0</td>\n",
       "      <td>-25.0</td>\n",
       "      <td>67.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>-2.0</td>\n",
       "      <td>75.0</td>\n",
       "      <td>-45.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>54.0</td>\n",
       "      <td>-29.0</td>\n",
       "      <td>52.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>-42.0</td>\n",
       "      <td>-49.0</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>12.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>27.0</td>\n",
       "      <td>60.0</td>\n",
       "      <td>11.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>16.0</td>\n",
       "      <td>24.0</td>\n",
       "      <td>18.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>-52.0</td>\n",
       "      <td>-70.0</td>\n",
       "      <td>-40.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>46.0</td>\n",
       "      <td>56.0</td>\n",
       "      <td>-4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>-81.0</td>\n",
       "      <td>-63.0</td>\n",
       "      <td>73.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>-3.0</td>\n",
       "      <td>34.0</td>\n",
       "      <td>-20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>58.0</td>\n",
       "      <td>-46.0</td>\n",
       "      <td>-27.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>-32.0</td>\n",
       "      <td>23.0</td>\n",
       "      <td>-18.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>32.0</td>\n",
       "      <td>-16.0</td>\n",
       "      <td>30.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>17.0</td>\n",
       "      <td>85.0</td>\n",
       "      <td>-39.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>-70.0</td>\n",
       "      <td>-14.0</td>\n",
       "      <td>-1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>U</th>\n",
       "      <td>-6.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>73.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A     NaN         NaN    NaN\n",
       "B   -16.0        28.0   -9.0\n",
       "C     5.0       -25.0   67.0\n",
       "D    -2.0        75.0  -45.0\n",
       "E    54.0       -29.0   52.0\n",
       "F   -42.0       -49.0    2.0\n",
       "H    12.0         3.0    NaN\n",
       "I     3.0         4.0    NaN\n",
       "J    27.0        60.0   11.0\n",
       "K    16.0        24.0   18.0\n",
       "L   -52.0       -70.0  -40.0\n",
       "M    46.0        56.0   -4.0\n",
       "N   -81.0       -63.0   73.0\n",
       "O    -3.0        34.0  -20.0\n",
       "P    58.0       -46.0  -27.0\n",
       "Q   -32.0        23.0  -18.0\n",
       "R    32.0       -16.0   30.0\n",
       "S    17.0        85.0  -39.0\n",
       "T   -70.0       -14.0   -1.0\n",
       "U    -6.0         8.0   73.0"
      ]
     },
     "execution_count": 227,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.diff()  #差分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 228,
   "id": "younger-bumper",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>-0.421</td>\n",
       "      <td>7.000</td>\n",
       "      <td>-0.281</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>0.227</td>\n",
       "      <td>-0.781</td>\n",
       "      <td>2.913</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>-0.074</td>\n",
       "      <td>10.714</td>\n",
       "      <td>-0.500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>2.160</td>\n",
       "      <td>-0.354</td>\n",
       "      <td>1.156</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>-0.532</td>\n",
       "      <td>-0.925</td>\n",
       "      <td>0.021</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>0.324</td>\n",
       "      <td>0.750</td>\n",
       "      <td>0.000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>0.061</td>\n",
       "      <td>0.571</td>\n",
       "      <td>-0.636</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>0.519</td>\n",
       "      <td>5.455</td>\n",
       "      <td>0.306</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>0.203</td>\n",
       "      <td>0.338</td>\n",
       "      <td>0.383</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>-0.547</td>\n",
       "      <td>-0.737</td>\n",
       "      <td>-0.615</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>1.070</td>\n",
       "      <td>2.240</td>\n",
       "      <td>-0.160</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>-0.910</td>\n",
       "      <td>-0.778</td>\n",
       "      <td>3.476</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>-0.375</td>\n",
       "      <td>1.889</td>\n",
       "      <td>-0.213</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>11.600</td>\n",
       "      <td>-0.885</td>\n",
       "      <td>-0.365</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>-0.508</td>\n",
       "      <td>3.833</td>\n",
       "      <td>-0.383</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>1.032</td>\n",
       "      <td>-0.552</td>\n",
       "      <td>1.034</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>0.270</td>\n",
       "      <td>6.538</td>\n",
       "      <td>-0.661</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>-0.875</td>\n",
       "      <td>-0.143</td>\n",
       "      <td>-0.050</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>U</th>\n",
       "      <td>-0.600</td>\n",
       "      <td>0.095</td>\n",
       "      <td>3.842</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A     NaN         NaN    NaN\n",
       "B  -0.421       7.000 -0.281\n",
       "C   0.227      -0.781  2.913\n",
       "D  -0.074      10.714 -0.500\n",
       "E   2.160      -0.354  1.156\n",
       "F  -0.532      -0.925  0.021\n",
       "H   0.324       0.750  0.000\n",
       "I   0.061       0.571 -0.636\n",
       "J   0.519       5.455  0.306\n",
       "K   0.203       0.338  0.383\n",
       "L  -0.547      -0.737 -0.615\n",
       "M   1.070       2.240 -0.160\n",
       "N  -0.910      -0.778  3.476\n",
       "O  -0.375       1.889 -0.213\n",
       "P  11.600      -0.885 -0.365\n",
       "Q  -0.508       3.833 -0.383\n",
       "R   1.032      -0.552  1.034\n",
       "S   0.270       6.538 -0.661\n",
       "T  -0.875      -0.143 -0.050\n",
       "U  -0.600       0.095  3.842"
      ]
     },
     "execution_count": 228,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.pct_change().round(3)# 计算百分⽐变化"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "located-london",
   "metadata": {},
   "source": [
    "### 高级统计指标"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 229,
   "id": "simple-model",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Python</th>\n",
       "      <td>848.786842</td>\n",
       "      <td>209.168421</td>\n",
       "      <td>-177.730994</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>209.168421</td>\n",
       "      <td>1259.642105</td>\n",
       "      <td>-185.096491</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>-177.730994</td>\n",
       "      <td>-185.096491</td>\n",
       "      <td>868.690058</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                Python   Tensorflow       Keras\n",
       "Python      848.786842   209.168421 -177.730994\n",
       "Tensorflow  209.168421  1259.642105 -185.096491\n",
       "Keras      -177.730994  -185.096491  868.690058"
      ]
     },
     "execution_count": 229,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.cov()  #协方差：自己和别人计算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 230,
   "id": "english-poster",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Python         848.786842\n",
       "Tensorflow    1259.642105\n",
       "Keras          868.690058\n",
       "dtype: float64"
      ]
     },
     "execution_count": 230,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.var() #方差：自己和自己计算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 231,
   "id": "governmental-variable",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "209.16842105263163"
      ]
     },
     "execution_count": 231,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['Python'].cov(df['Tensorflow'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 232,
   "id": "purple-bruce",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Python</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.202289</td>\n",
       "      <td>-0.201569</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tensorflow</th>\n",
       "      <td>0.202289</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>-0.177416</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Keras</th>\n",
       "      <td>-0.201569</td>\n",
       "      <td>-0.177416</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              Python  Tensorflow     Keras\n",
       "Python      1.000000    0.202289 -0.201569\n",
       "Tensorflow  0.202289    1.000000 -0.177416\n",
       "Keras      -0.201569   -0.177416  1.000000"
      ]
     },
     "execution_count": 232,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.corr()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "reliable-montgomery",
   "metadata": {},
   "source": [
    "## 排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 233,
   "id": "scheduled-combining",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>38</td>\n",
       "      <td>4</td>\n",
       "      <td>32.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>22</td>\n",
       "      <td>32</td>\n",
       "      <td>23.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>27</td>\n",
       "      <td>7</td>\n",
       "      <td>90.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>25</td>\n",
       "      <td>82</td>\n",
       "      <td>45.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>79</td>\n",
       "      <td>53</td>\n",
       "      <td>97.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>37</td>\n",
       "      <td>4</td>\n",
       "      <td>99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>49</td>\n",
       "      <td>7</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>52</td>\n",
       "      <td>11</td>\n",
       "      <td>36.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>79</td>\n",
       "      <td>71</td>\n",
       "      <td>47.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>95</td>\n",
       "      <td>95</td>\n",
       "      <td>65.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>43</td>\n",
       "      <td>25</td>\n",
       "      <td>25.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>89</td>\n",
       "      <td>81</td>\n",
       "      <td>21.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>8</td>\n",
       "      <td>18</td>\n",
       "      <td>94.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>5</td>\n",
       "      <td>52</td>\n",
       "      <td>74.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>63</td>\n",
       "      <td>6</td>\n",
       "      <td>47.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>31</td>\n",
       "      <td>29</td>\n",
       "      <td>29.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>63</td>\n",
       "      <td>13</td>\n",
       "      <td>59.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>80</td>\n",
       "      <td>98</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>10</td>\n",
       "      <td>84</td>\n",
       "      <td>19.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>U</th>\n",
       "      <td>4</td>\n",
       "      <td>92</td>\n",
       "      <td>92.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "A      38           4   32.0\n",
       "B      22          32   23.0\n",
       "C      27           7   90.0\n",
       "D      25          82   45.0\n",
       "E      79          53   97.0\n",
       "F      37           4   99.0\n",
       "H      49           7    NaN\n",
       "I      52          11   36.0\n",
       "J      79          71   47.0\n",
       "K      95          95   65.0\n",
       "L      43          25   25.0\n",
       "M      89          81   21.0\n",
       "N       8          18   94.0\n",
       "O       5          52   74.0\n",
       "P      63           6   47.0\n",
       "Q      31          29   29.0\n",
       "R      63          13   59.0\n",
       "S      80          98   20.0\n",
       "T      10          84   19.0\n",
       "U       4          92   92.0"
      ]
     },
     "execution_count": 233,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 236,
   "id": "amateur-reducing",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>U</th>\n",
       "      <td>4</td>\n",
       "      <td>92</td>\n",
       "      <td>92.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>10</td>\n",
       "      <td>84</td>\n",
       "      <td>19.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>80</td>\n",
       "      <td>98</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>63</td>\n",
       "      <td>13</td>\n",
       "      <td>59.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>31</td>\n",
       "      <td>29</td>\n",
       "      <td>29.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>63</td>\n",
       "      <td>6</td>\n",
       "      <td>47.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>5</td>\n",
       "      <td>52</td>\n",
       "      <td>74.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>8</td>\n",
       "      <td>18</td>\n",
       "      <td>94.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>89</td>\n",
       "      <td>81</td>\n",
       "      <td>21.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>43</td>\n",
       "      <td>25</td>\n",
       "      <td>25.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>95</td>\n",
       "      <td>95</td>\n",
       "      <td>65.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>79</td>\n",
       "      <td>71</td>\n",
       "      <td>47.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>52</td>\n",
       "      <td>11</td>\n",
       "      <td>36.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>49</td>\n",
       "      <td>7</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>37</td>\n",
       "      <td>4</td>\n",
       "      <td>99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>79</td>\n",
       "      <td>53</td>\n",
       "      <td>97.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>25</td>\n",
       "      <td>82</td>\n",
       "      <td>45.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>27</td>\n",
       "      <td>7</td>\n",
       "      <td>90.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>22</td>\n",
       "      <td>32</td>\n",
       "      <td>23.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>38</td>\n",
       "      <td>4</td>\n",
       "      <td>32.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "U       4          92   92.0\n",
       "T      10          84   19.0\n",
       "S      80          98   20.0\n",
       "R      63          13   59.0\n",
       "Q      31          29   29.0\n",
       "P      63           6   47.0\n",
       "O       5          52   74.0\n",
       "N       8          18   94.0\n",
       "M      89          81   21.0\n",
       "L      43          25   25.0\n",
       "K      95          95   65.0\n",
       "J      79          71   47.0\n",
       "I      52          11   36.0\n",
       "H      49           7    NaN\n",
       "F      37           4   99.0\n",
       "E      79          53   97.0\n",
       "D      25          82   45.0\n",
       "C      27           7   90.0\n",
       "B      22          32   23.0\n",
       "A      38           4   32.0"
      ]
     },
     "execution_count": 236,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.sort_index(axis=0,ascending=False)#降序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 239,
   "id": "worthy-overall",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "d:\\python3.7.3\\lib\\site-packages\\ipykernel_launcher.py:1: FutureWarning: by argument to sort_index is deprecated, please use .sort_values(by=...)\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>U</th>\n",
       "      <td>4</td>\n",
       "      <td>92</td>\n",
       "      <td>92.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>5</td>\n",
       "      <td>52</td>\n",
       "      <td>74.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>8</td>\n",
       "      <td>18</td>\n",
       "      <td>94.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>10</td>\n",
       "      <td>84</td>\n",
       "      <td>19.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>22</td>\n",
       "      <td>32</td>\n",
       "      <td>23.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>25</td>\n",
       "      <td>82</td>\n",
       "      <td>45.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>27</td>\n",
       "      <td>7</td>\n",
       "      <td>90.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>31</td>\n",
       "      <td>29</td>\n",
       "      <td>29.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>37</td>\n",
       "      <td>4</td>\n",
       "      <td>99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>38</td>\n",
       "      <td>4</td>\n",
       "      <td>32.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>43</td>\n",
       "      <td>25</td>\n",
       "      <td>25.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>49</td>\n",
       "      <td>7</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>52</td>\n",
       "      <td>11</td>\n",
       "      <td>36.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>63</td>\n",
       "      <td>6</td>\n",
       "      <td>47.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>63</td>\n",
       "      <td>13</td>\n",
       "      <td>59.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>79</td>\n",
       "      <td>53</td>\n",
       "      <td>97.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>79</td>\n",
       "      <td>71</td>\n",
       "      <td>47.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>80</td>\n",
       "      <td>98</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>89</td>\n",
       "      <td>81</td>\n",
       "      <td>21.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>95</td>\n",
       "      <td>95</td>\n",
       "      <td>65.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "U       4          92   92.0\n",
       "O       5          52   74.0\n",
       "N       8          18   94.0\n",
       "T      10          84   19.0\n",
       "B      22          32   23.0\n",
       "D      25          82   45.0\n",
       "C      27           7   90.0\n",
       "Q      31          29   29.0\n",
       "F      37           4   99.0\n",
       "A      38           4   32.0\n",
       "L      43          25   25.0\n",
       "H      49           7    NaN\n",
       "I      52          11   36.0\n",
       "P      63           6   47.0\n",
       "R      63          13   59.0\n",
       "E      79          53   97.0\n",
       "J      79          71   47.0\n",
       "S      80          98   20.0\n",
       "M      89          81   21.0\n",
       "K      95          95   65.0"
      ]
     },
     "execution_count": 239,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.sort_index(axis=0,by='Python',ascending=True)#升序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 240,
   "id": "coated-housing",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "d:\\python3.7.3\\lib\\site-packages\\ipykernel_launcher.py:1: FutureWarning: by argument to sort_index is deprecated, please use .sort_values(by=...)\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>U</th>\n",
       "      <td>4</td>\n",
       "      <td>92</td>\n",
       "      <td>92.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>O</th>\n",
       "      <td>5</td>\n",
       "      <td>52</td>\n",
       "      <td>74.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>N</th>\n",
       "      <td>8</td>\n",
       "      <td>18</td>\n",
       "      <td>94.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>T</th>\n",
       "      <td>10</td>\n",
       "      <td>84</td>\n",
       "      <td>19.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>B</th>\n",
       "      <td>22</td>\n",
       "      <td>32</td>\n",
       "      <td>23.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>D</th>\n",
       "      <td>25</td>\n",
       "      <td>82</td>\n",
       "      <td>45.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>C</th>\n",
       "      <td>27</td>\n",
       "      <td>7</td>\n",
       "      <td>90.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q</th>\n",
       "      <td>31</td>\n",
       "      <td>29</td>\n",
       "      <td>29.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>37</td>\n",
       "      <td>4</td>\n",
       "      <td>99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>A</th>\n",
       "      <td>38</td>\n",
       "      <td>4</td>\n",
       "      <td>32.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L</th>\n",
       "      <td>43</td>\n",
       "      <td>25</td>\n",
       "      <td>25.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>H</th>\n",
       "      <td>49</td>\n",
       "      <td>7</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>I</th>\n",
       "      <td>52</td>\n",
       "      <td>11</td>\n",
       "      <td>36.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>P</th>\n",
       "      <td>63</td>\n",
       "      <td>6</td>\n",
       "      <td>47.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>R</th>\n",
       "      <td>63</td>\n",
       "      <td>13</td>\n",
       "      <td>59.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>79</td>\n",
       "      <td>53</td>\n",
       "      <td>97.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>79</td>\n",
       "      <td>71</td>\n",
       "      <td>47.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>80</td>\n",
       "      <td>98</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>89</td>\n",
       "      <td>81</td>\n",
       "      <td>21.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>95</td>\n",
       "      <td>95</td>\n",
       "      <td>65.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "U       4          92   92.0\n",
       "O       5          52   74.0\n",
       "N       8          18   94.0\n",
       "T      10          84   19.0\n",
       "B      22          32   23.0\n",
       "D      25          82   45.0\n",
       "C      27           7   90.0\n",
       "Q      31          29   29.0\n",
       "F      37           4   99.0\n",
       "A      38           4   32.0\n",
       "L      43          25   25.0\n",
       "H      49           7    NaN\n",
       "I      52          11   36.0\n",
       "P      63           6   47.0\n",
       "R      63          13   59.0\n",
       "E      79          53   97.0\n",
       "J      79          71   47.0\n",
       "S      80          98   20.0\n",
       "M      89          81   21.0\n",
       "K      95          95   65.0"
      ]
     },
     "execution_count": 240,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.sort_index(axis=0,by=['Python','Tensorflow'],ascending=True)#升序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 241,
   "id": "afraid-judge",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>K</th>\n",
       "      <td>95</td>\n",
       "      <td>95</td>\n",
       "      <td>65.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>89</td>\n",
       "      <td>81</td>\n",
       "      <td>21.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>S</th>\n",
       "      <td>80</td>\n",
       "      <td>98</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>E</th>\n",
       "      <td>79</td>\n",
       "      <td>53</td>\n",
       "      <td>97.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>J</th>\n",
       "      <td>79</td>\n",
       "      <td>71</td>\n",
       "      <td>47.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Python  Tensorflow  Keras\n",
       "K      95          95   65.0\n",
       "M      89          81   21.0\n",
       "S      80          98   20.0\n",
       "E      79          53   97.0\n",
       "J      79          71   47.0"
      ]
     },
     "execution_count": 241,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.nlargest(n=5,columns='Python')#根据python排序，获取python最大的五个行的数据"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "random-jaguar",
   "metadata": {},
   "source": [
    "## 分箱操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 243,
   "id": "presidential-nudist",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>64</td>\n",
       "      <td>93</td>\n",
       "      <td>102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>16</td>\n",
       "      <td>54</td>\n",
       "      <td>104</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>79</td>\n",
       "      <td>132</td>\n",
       "      <td>137</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>49</td>\n",
       "      <td>136</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3</td>\n",
       "      <td>42</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>24</td>\n",
       "      <td>85</td>\n",
       "      <td>134</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>57</td>\n",
       "      <td>121</td>\n",
       "      <td>94</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>96</td>\n",
       "      <td>65</td>\n",
       "      <td>105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>60</td>\n",
       "      <td>41</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>132</td>\n",
       "      <td>115</td>\n",
       "      <td>125</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>65</td>\n",
       "      <td>28</td>\n",
       "      <td>97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>78</td>\n",
       "      <td>39</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>136</td>\n",
       "      <td>117</td>\n",
       "      <td>146</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>99</td>\n",
       "      <td>61</td>\n",
       "      <td>134</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>108</td>\n",
       "      <td>70</td>\n",
       "      <td>128</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>74</td>\n",
       "      <td>112</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>18</td>\n",
       "      <td>96</td>\n",
       "      <td>37</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>19</td>\n",
       "      <td>128</td>\n",
       "      <td>93</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>49</td>\n",
       "      <td>128</td>\n",
       "      <td>71</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>25</td>\n",
       "      <td>146</td>\n",
       "      <td>136</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>75</td>\n",
       "      <td>107</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>2</td>\n",
       "      <td>7</td>\n",
       "      <td>54</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>61</td>\n",
       "      <td>58</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>93</td>\n",
       "      <td>42</td>\n",
       "      <td>36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>107</td>\n",
       "      <td>149</td>\n",
       "      <td>110</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>73</td>\n",
       "      <td>49</td>\n",
       "      <td>122</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>98</td>\n",
       "      <td>144</td>\n",
       "      <td>67</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>109</td>\n",
       "      <td>132</td>\n",
       "      <td>88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>122</td>\n",
       "      <td>113</td>\n",
       "      <td>51</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>75</td>\n",
       "      <td>83</td>\n",
       "      <td>117</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>55</td>\n",
       "      <td>148</td>\n",
       "      <td>117</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>124</td>\n",
       "      <td>39</td>\n",
       "      <td>140</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>124</td>\n",
       "      <td>11</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>84</td>\n",
       "      <td>0</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>74</th>\n",
       "      <td>40</td>\n",
       "      <td>86</td>\n",
       "      <td>124</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <td>10</td>\n",
       "      <td>22</td>\n",
       "      <td>44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>54</td>\n",
       "      <td>15</td>\n",
       "      <td>107</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>50</td>\n",
       "      <td>56</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>19</td>\n",
       "      <td>109</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>57</td>\n",
       "      <td>53</td>\n",
       "      <td>130</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>52</td>\n",
       "      <td>37</td>\n",
       "      <td>124</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>1</td>\n",
       "      <td>90</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>123</td>\n",
       "      <td>4</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>50</td>\n",
       "      <td>81</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>47</td>\n",
       "      <td>34</td>\n",
       "      <td>85</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>85</th>\n",
       "      <td>35</td>\n",
       "      <td>62</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>86</th>\n",
       "      <td>121</td>\n",
       "      <td>119</td>\n",
       "      <td>132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>128</td>\n",
       "      <td>65</td>\n",
       "      <td>96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>115</td>\n",
       "      <td>4</td>\n",
       "      <td>47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89</th>\n",
       "      <td>108</td>\n",
       "      <td>12</td>\n",
       "      <td>111</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>90</th>\n",
       "      <td>59</td>\n",
       "      <td>109</td>\n",
       "      <td>53</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>91</th>\n",
       "      <td>31</td>\n",
       "      <td>37</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92</th>\n",
       "      <td>122</td>\n",
       "      <td>131</td>\n",
       "      <td>142</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93</th>\n",
       "      <td>99</td>\n",
       "      <td>70</td>\n",
       "      <td>32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>94</th>\n",
       "      <td>144</td>\n",
       "      <td>11</td>\n",
       "      <td>68</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>45</td>\n",
       "      <td>83</td>\n",
       "      <td>142</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>115</td>\n",
       "      <td>48</td>\n",
       "      <td>139</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>69</td>\n",
       "      <td>16</td>\n",
       "      <td>120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>21</td>\n",
       "      <td>48</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>133</td>\n",
       "      <td>104</td>\n",
       "      <td>47</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    Python  Tensorflow  Keras\n",
       "0       64          93    102\n",
       "1       16          54    104\n",
       "2       79         132    137\n",
       "3       49         136     94\n",
       "4        3          42     23\n",
       "5       24          85    134\n",
       "6       57         121     94\n",
       "7       96          65    105\n",
       "8       60          41     96\n",
       "9      132         115    125\n",
       "10      65          28     97\n",
       "11      78          39      3\n",
       "12     136         117    146\n",
       "13      99          61    134\n",
       "14     108          70    128\n",
       "15      74         112      4\n",
       "16      18          96     37\n",
       "17      19         128     93\n",
       "18      49         128     71\n",
       "19      25         146    136\n",
       "20      75         107     46\n",
       "21       2           7     54\n",
       "22      61          58     96\n",
       "23      93          42     36\n",
       "24     107         149    110\n",
       "25      73          49    122\n",
       "26      98         144     67\n",
       "27     109         132     88\n",
       "28     122         113     51\n",
       "29      75          83    117\n",
       "..     ...         ...    ...\n",
       "70      55         148    117\n",
       "71     124          39    140\n",
       "72     124          11     30\n",
       "73      84           0     48\n",
       "74      40          86    124\n",
       "75      10          22     44\n",
       "76      54          15    107\n",
       "77      50          56     99\n",
       "78      19         109     12\n",
       "79      57          53    130\n",
       "80      52          37    124\n",
       "81       1          90     18\n",
       "82     123           4     96\n",
       "83      50          81      4\n",
       "84      47          34     85\n",
       "85      35          62     43\n",
       "86     121         119    132\n",
       "87     128          65     96\n",
       "88     115           4     47\n",
       "89     108          12    111\n",
       "90      59         109     53\n",
       "91      31          37     46\n",
       "92     122         131    142\n",
       "93      99          70     32\n",
       "94     144          11     68\n",
       "95      45          83    142\n",
       "96     115          48    139\n",
       "97      69          16    120\n",
       "98      21          48     84\n",
       "99     133         104     47\n",
       "\n",
       "[100 rows x 3 columns]"
      ]
     },
     "execution_count": 243,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data = np.random.randint(0,150,size = (100,3)),\n",
    " columns=['Python','Tensorflow','Keras'])\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 247,
   "id": "continuing-artist",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0      及格\n",
       "1     不及格\n",
       "2      中等\n",
       "3      及格\n",
       "4     不及格\n",
       "5     不及格\n",
       "6      及格\n",
       "7      中等\n",
       "8      及格\n",
       "9      优秀\n",
       "10     及格\n",
       "11     中等\n",
       "12     优秀\n",
       "13     中等\n",
       "14     中等\n",
       "15     及格\n",
       "16    不及格\n",
       "17    不及格\n",
       "18     及格\n",
       "19    不及格\n",
       "20     及格\n",
       "21    不及格\n",
       "22     及格\n",
       "23     中等\n",
       "24     中等\n",
       "25     及格\n",
       "26     中等\n",
       "27     中等\n",
       "28     优秀\n",
       "29     及格\n",
       "     ... \n",
       "70     及格\n",
       "71     优秀\n",
       "72     优秀\n",
       "73     中等\n",
       "74     及格\n",
       "75    不及格\n",
       "76     及格\n",
       "77     及格\n",
       "78    不及格\n",
       "79     及格\n",
       "80     及格\n",
       "81    不及格\n",
       "82     优秀\n",
       "83     及格\n",
       "84     及格\n",
       "85    不及格\n",
       "86     优秀\n",
       "87     优秀\n",
       "88     优秀\n",
       "89     中等\n",
       "90     及格\n",
       "91    不及格\n",
       "92     优秀\n",
       "93     中等\n",
       "94     优秀\n",
       "95     及格\n",
       "96     优秀\n",
       "97     及格\n",
       "98    不及格\n",
       "99     优秀\n",
       "Name: Python, Length: 100, dtype: category\n",
       "Categories (4, object): [不及格 < 及格 < 中等 < 优秀]"
      ]
     },
     "execution_count": 247,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 1、等宽分箱\n",
    "pd.cut(df.Python,bins = 4,\n",
    "#        labels=['不及格','及格','中等','优秀'],\n",
    "      right = True#表明 （0,151）的右边闭区间，默认闭区间\n",
    "      )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 250,
   "id": "retained-victoria",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Keras</th>\n",
       "      <th>等级</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>64</td>\n",
       "      <td>93</td>\n",
       "      <td>102</td>\n",
       "      <td>良好</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>16</td>\n",
       "      <td>54</td>\n",
       "      <td>104</td>\n",
       "      <td>良好</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>79</td>\n",
       "      <td>132</td>\n",
       "      <td>137</td>\n",
       "      <td>优秀</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>49</td>\n",
       "      <td>136</td>\n",
       "      <td>94</td>\n",
       "      <td>良好</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3</td>\n",
       "      <td>42</td>\n",
       "      <td>23</td>\n",
       "      <td>不及格</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>24</td>\n",
       "      <td>85</td>\n",
       "      <td>134</td>\n",
       "      <td>优秀</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>57</td>\n",
       "      <td>121</td>\n",
       "      <td>94</td>\n",
       "      <td>良好</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>96</td>\n",
       "      <td>65</td>\n",
       "      <td>105</td>\n",
       "      <td>良好</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>60</td>\n",
       "      <td>41</td>\n",
       "      <td>96</td>\n",
       "      <td>良好</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>132</td>\n",
       "      <td>115</td>\n",
       "      <td>125</td>\n",
       "      <td>优秀</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>65</td>\n",
       "      <td>28</td>\n",
       "      <td>97</td>\n",
       "      <td>良好</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>78</td>\n",
       "      <td>39</td>\n",
       "      <td>3</td>\n",
       "      <td>不及格</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>136</td>\n",
       "      <td>117</td>\n",
       "      <td>146</td>\n",
       "      <td>优秀</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>99</td>\n",
       "      <td>61</td>\n",
       "      <td>134</td>\n",
       "      <td>优秀</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>108</td>\n",
       "      <td>70</td>\n",
       "      <td>128</td>\n",
       "      <td>优秀</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>74</td>\n",
       "      <td>112</td>\n",
       "      <td>4</td>\n",
       "      <td>不及格</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>18</td>\n",
       "      <td>96</td>\n",
       "      <td>37</td>\n",
       "      <td>不及格</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>19</td>\n",
       "      <td>128</td>\n",
       "      <td>93</td>\n",
       "      <td>良好</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>49</td>\n",
       "      <td>128</td>\n",
       "      <td>71</td>\n",
       "      <td>中等</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>25</td>\n",
       "      <td>146</td>\n",
       "      <td>136</td>\n",
       "      <td>优秀</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>75</td>\n",
       "      <td>107</td>\n",
       "      <td>46</td>\n",
       "      <td>不及格</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>2</td>\n",
       "      <td>7</td>\n",
       "      <td>54</td>\n",
       "      <td>不及格</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>61</td>\n",
       "      <td>58</td>\n",
       "      <td>96</td>\n",
       "      <td>良好</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>93</td>\n",
       "      <td>42</td>\n",
       "      <td>36</td>\n",
       "      <td>不及格</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>107</td>\n",
       "      <td>149</td>\n",
       "      <td>110</td>\n",
       "      <td>良好</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>73</td>\n",
       "      <td>49</td>\n",
       "      <td>122</td>\n",
       "      <td>优秀</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>98</td>\n",
       "      <td>144</td>\n",
       "      <td>67</td>\n",
       "      <td>中等</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>109</td>\n",
       "      <td>132</td>\n",
       "      <td>88</td>\n",
       "      <td>中等</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>122</td>\n",
       "      <td>113</td>\n",
       "      <td>51</td>\n",
       "      <td>不及格</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>75</td>\n",
       "      <td>83</td>\n",
       "      <td>117</td>\n",
       "      <td>良好</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>55</td>\n",
       "      <td>148</td>\n",
       "      <td>117</td>\n",
       "      <td>良好</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>124</td>\n",
       "      <td>39</td>\n",
       "      <td>140</td>\n",
       "      <td>优秀</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>124</td>\n",
       "      <td>11</td>\n",
       "      <td>30</td>\n",
       "      <td>不及格</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>84</td>\n",
       "      <td>0</td>\n",
       "      <td>48</td>\n",
       "      <td>不及格</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>74</th>\n",
       "      <td>40</td>\n",
       "      <td>86</td>\n",
       "      <td>124</td>\n",
       "      <td>优秀</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <td>10</td>\n",
       "      <td>22</td>\n",
       "      <td>44</td>\n",
       "      <td>不及格</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>54</td>\n",
       "      <td>15</td>\n",
       "      <td>107</td>\n",
       "      <td>良好</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>50</td>\n",
       "      <td>56</td>\n",
       "      <td>99</td>\n",
       "      <td>良好</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>19</td>\n",
       "      <td>109</td>\n",
       "      <td>12</td>\n",
       "      <td>不及格</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>57</td>\n",
       "      <td>53</td>\n",
       "      <td>130</td>\n",
       "      <td>优秀</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>52</td>\n",
       "      <td>37</td>\n",
       "      <td>124</td>\n",
       "      <td>优秀</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>1</td>\n",
       "      <td>90</td>\n",
       "      <td>18</td>\n",
       "      <td>不及格</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>123</td>\n",
       "      <td>4</td>\n",
       "      <td>96</td>\n",
       "      <td>良好</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>50</td>\n",
       "      <td>81</td>\n",
       "      <td>4</td>\n",
       "      <td>不及格</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>47</td>\n",
       "      <td>34</td>\n",
       "      <td>85</td>\n",
       "      <td>中等</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>85</th>\n",
       "      <td>35</td>\n",
       "      <td>62</td>\n",
       "      <td>43</td>\n",
       "      <td>不及格</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>86</th>\n",
       "      <td>121</td>\n",
       "      <td>119</td>\n",
       "      <td>132</td>\n",
       "      <td>优秀</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>128</td>\n",
       "      <td>65</td>\n",
       "      <td>96</td>\n",
       "      <td>良好</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>115</td>\n",
       "      <td>4</td>\n",
       "      <td>47</td>\n",
       "      <td>不及格</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89</th>\n",
       "      <td>108</td>\n",
       "      <td>12</td>\n",
       "      <td>111</td>\n",
       "      <td>良好</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>90</th>\n",
       "      <td>59</td>\n",
       "      <td>109</td>\n",
       "      <td>53</td>\n",
       "      <td>不及格</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>91</th>\n",
       "      <td>31</td>\n",
       "      <td>37</td>\n",
       "      <td>46</td>\n",
       "      <td>不及格</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92</th>\n",
       "      <td>122</td>\n",
       "      <td>131</td>\n",
       "      <td>142</td>\n",
       "      <td>优秀</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93</th>\n",
       "      <td>99</td>\n",
       "      <td>70</td>\n",
       "      <td>32</td>\n",
       "      <td>不及格</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>94</th>\n",
       "      <td>144</td>\n",
       "      <td>11</td>\n",
       "      <td>68</td>\n",
       "      <td>中等</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>45</td>\n",
       "      <td>83</td>\n",
       "      <td>142</td>\n",
       "      <td>优秀</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>115</td>\n",
       "      <td>48</td>\n",
       "      <td>139</td>\n",
       "      <td>优秀</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>69</td>\n",
       "      <td>16</td>\n",
       "      <td>120</td>\n",
       "      <td>优秀</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>21</td>\n",
       "      <td>48</td>\n",
       "      <td>84</td>\n",
       "      <td>中等</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>133</td>\n",
       "      <td>104</td>\n",
       "      <td>47</td>\n",
       "      <td>不及格</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    Python  Tensorflow  Keras   等级\n",
       "0       64          93    102   良好\n",
       "1       16          54    104   良好\n",
       "2       79         132    137   优秀\n",
       "3       49         136     94   良好\n",
       "4        3          42     23  不及格\n",
       "5       24          85    134   优秀\n",
       "6       57         121     94   良好\n",
       "7       96          65    105   良好\n",
       "8       60          41     96   良好\n",
       "9      132         115    125   优秀\n",
       "10      65          28     97   良好\n",
       "11      78          39      3  不及格\n",
       "12     136         117    146   优秀\n",
       "13      99          61    134   优秀\n",
       "14     108          70    128   优秀\n",
       "15      74         112      4  不及格\n",
       "16      18          96     37  不及格\n",
       "17      19         128     93   良好\n",
       "18      49         128     71   中等\n",
       "19      25         146    136   优秀\n",
       "20      75         107     46  不及格\n",
       "21       2           7     54  不及格\n",
       "22      61          58     96   良好\n",
       "23      93          42     36  不及格\n",
       "24     107         149    110   良好\n",
       "25      73          49    122   优秀\n",
       "26      98         144     67   中等\n",
       "27     109         132     88   中等\n",
       "28     122         113     51  不及格\n",
       "29      75          83    117   良好\n",
       "..     ...         ...    ...  ...\n",
       "70      55         148    117   良好\n",
       "71     124          39    140   优秀\n",
       "72     124          11     30  不及格\n",
       "73      84           0     48  不及格\n",
       "74      40          86    124   优秀\n",
       "75      10          22     44  不及格\n",
       "76      54          15    107   良好\n",
       "77      50          56     99   良好\n",
       "78      19         109     12  不及格\n",
       "79      57          53    130   优秀\n",
       "80      52          37    124   优秀\n",
       "81       1          90     18  不及格\n",
       "82     123           4     96   良好\n",
       "83      50          81      4  不及格\n",
       "84      47          34     85   中等\n",
       "85      35          62     43  不及格\n",
       "86     121         119    132   优秀\n",
       "87     128          65     96   良好\n",
       "88     115           4     47  不及格\n",
       "89     108          12    111   良好\n",
       "90      59         109     53  不及格\n",
       "91      31          37     46  不及格\n",
       "92     122         131    142   优秀\n",
       "93      99          70     32  不及格\n",
       "94     144          11     68   中等\n",
       "95      45          83    142   优秀\n",
       "96     115          48    139   优秀\n",
       "97      69          16    120   优秀\n",
       "98      21          48     84   中等\n",
       "99     133         104     47  不及格\n",
       "\n",
       "[100 rows x 4 columns]"
      ]
     },
     "execution_count": 250,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2.指定宽度分箱\n",
    "df['等级'] = pd.cut(df.Keras,#分箱数据\n",
    " bins = [0,60,90,120,150],#分箱断点\n",
    " right = False,# 左闭右开\n",
    " labels=['不及格','中等','良好','优秀'])# 分箱后分类\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 251,
   "id": "adopted-running",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     中\n",
       "1     差\n",
       "2     良\n",
       "3     中\n",
       "4     差\n",
       "5     差\n",
       "6     中\n",
       "7     良\n",
       "8     中\n",
       "9     优\n",
       "10    中\n",
       "11    良\n",
       "12    优\n",
       "13    良\n",
       "14    优\n",
       "15    良\n",
       "16    差\n",
       "17    差\n",
       "18    中\n",
       "19    差\n",
       "20    良\n",
       "21    差\n",
       "22    中\n",
       "23    良\n",
       "24    良\n",
       "25    良\n",
       "26    良\n",
       "27    优\n",
       "28    优\n",
       "29    良\n",
       "     ..\n",
       "70    中\n",
       "71    优\n",
       "72    优\n",
       "73    良\n",
       "74    差\n",
       "75    差\n",
       "76    中\n",
       "77    中\n",
       "78    差\n",
       "79    中\n",
       "80    中\n",
       "81    差\n",
       "82    优\n",
       "83    中\n",
       "84    中\n",
       "85    差\n",
       "86    优\n",
       "87    优\n",
       "88    优\n",
       "89    优\n",
       "90    中\n",
       "91    差\n",
       "92    优\n",
       "93    良\n",
       "94    优\n",
       "95    中\n",
       "96    优\n",
       "97    良\n",
       "98    差\n",
       "99    优\n",
       "Name: Python, Length: 100, dtype: category\n",
       "Categories (4, object): [差 < 中 < 良 < 优]"
      ]
     },
     "execution_count": 251,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3、等频分箱\n",
    "pd.qcut(df.Python,q = 4,# 4等分\n",
    " labels=['差','中','良','优']) # 分箱后分类"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 253,
   "id": "growing-sheriff",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "差    26\n",
       "优    25\n",
       "良    25\n",
       "中    24\n",
       "Name: Python, dtype: int64"
      ]
     },
     "execution_count": 253,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.qcut(df.Python,q = 4, labels=['差','中','良','优']).value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "graphic-stockholm",
   "metadata": {},
   "source": [
    "## 分组聚合"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "polish-garbage",
   "metadata": {},
   "source": [
    "### 分组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 256,
   "id": "gross-victim",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sex</th>\n",
       "      <th>class</th>\n",
       "      <th>Python</th>\n",
       "      <th>Keras</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Java</th>\n",
       "      <th>C++</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>男</td>\n",
       "      <td>1</td>\n",
       "      <td>114</td>\n",
       "      <td>150</td>\n",
       "      <td>87</td>\n",
       "      <td>3</td>\n",
       "      <td>149</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>男</td>\n",
       "      <td>7</td>\n",
       "      <td>134</td>\n",
       "      <td>150</td>\n",
       "      <td>36</td>\n",
       "      <td>8</td>\n",
       "      <td>57</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>男</td>\n",
       "      <td>1</td>\n",
       "      <td>123</td>\n",
       "      <td>87</td>\n",
       "      <td>117</td>\n",
       "      <td>50</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>⼥</td>\n",
       "      <td>3</td>\n",
       "      <td>77</td>\n",
       "      <td>84</td>\n",
       "      <td>75</td>\n",
       "      <td>15</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>⼥</td>\n",
       "      <td>1</td>\n",
       "      <td>19</td>\n",
       "      <td>1</td>\n",
       "      <td>56</td>\n",
       "      <td>16</td>\n",
       "      <td>109</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>男</td>\n",
       "      <td>8</td>\n",
       "      <td>59</td>\n",
       "      <td>101</td>\n",
       "      <td>126</td>\n",
       "      <td>149</td>\n",
       "      <td>78</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>男</td>\n",
       "      <td>6</td>\n",
       "      <td>43</td>\n",
       "      <td>88</td>\n",
       "      <td>107</td>\n",
       "      <td>79</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>⼥</td>\n",
       "      <td>8</td>\n",
       "      <td>46</td>\n",
       "      <td>40</td>\n",
       "      <td>82</td>\n",
       "      <td>115</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>男</td>\n",
       "      <td>8</td>\n",
       "      <td>103</td>\n",
       "      <td>7</td>\n",
       "      <td>81</td>\n",
       "      <td>79</td>\n",
       "      <td>105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>男</td>\n",
       "      <td>3</td>\n",
       "      <td>137</td>\n",
       "      <td>89</td>\n",
       "      <td>36</td>\n",
       "      <td>38</td>\n",
       "      <td>118</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>⼥</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>110</td>\n",
       "      <td>130</td>\n",
       "      <td>150</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>男</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>26</td>\n",
       "      <td>57</td>\n",
       "      <td>106</td>\n",
       "      <td>102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>男</td>\n",
       "      <td>5</td>\n",
       "      <td>18</td>\n",
       "      <td>141</td>\n",
       "      <td>2</td>\n",
       "      <td>81</td>\n",
       "      <td>88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>⼥</td>\n",
       "      <td>4</td>\n",
       "      <td>102</td>\n",
       "      <td>21</td>\n",
       "      <td>103</td>\n",
       "      <td>24</td>\n",
       "      <td>72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>⼥</td>\n",
       "      <td>4</td>\n",
       "      <td>48</td>\n",
       "      <td>94</td>\n",
       "      <td>22</td>\n",
       "      <td>61</td>\n",
       "      <td>147</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>⼥</td>\n",
       "      <td>4</td>\n",
       "      <td>23</td>\n",
       "      <td>97</td>\n",
       "      <td>58</td>\n",
       "      <td>82</td>\n",
       "      <td>139</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>男</td>\n",
       "      <td>4</td>\n",
       "      <td>21</td>\n",
       "      <td>116</td>\n",
       "      <td>17</td>\n",
       "      <td>114</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>男</td>\n",
       "      <td>2</td>\n",
       "      <td>62</td>\n",
       "      <td>135</td>\n",
       "      <td>108</td>\n",
       "      <td>123</td>\n",
       "      <td>134</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>男</td>\n",
       "      <td>3</td>\n",
       "      <td>8</td>\n",
       "      <td>90</td>\n",
       "      <td>110</td>\n",
       "      <td>7</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>男</td>\n",
       "      <td>7</td>\n",
       "      <td>145</td>\n",
       "      <td>145</td>\n",
       "      <td>106</td>\n",
       "      <td>42</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>男</td>\n",
       "      <td>8</td>\n",
       "      <td>114</td>\n",
       "      <td>54</td>\n",
       "      <td>11</td>\n",
       "      <td>17</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>男</td>\n",
       "      <td>3</td>\n",
       "      <td>110</td>\n",
       "      <td>47</td>\n",
       "      <td>142</td>\n",
       "      <td>143</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>⼥</td>\n",
       "      <td>3</td>\n",
       "      <td>47</td>\n",
       "      <td>119</td>\n",
       "      <td>76</td>\n",
       "      <td>93</td>\n",
       "      <td>91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>⼥</td>\n",
       "      <td>8</td>\n",
       "      <td>88</td>\n",
       "      <td>31</td>\n",
       "      <td>68</td>\n",
       "      <td>132</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>男</td>\n",
       "      <td>5</td>\n",
       "      <td>99</td>\n",
       "      <td>95</td>\n",
       "      <td>82</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>男</td>\n",
       "      <td>5</td>\n",
       "      <td>108</td>\n",
       "      <td>119</td>\n",
       "      <td>77</td>\n",
       "      <td>105</td>\n",
       "      <td>115</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>男</td>\n",
       "      <td>6</td>\n",
       "      <td>14</td>\n",
       "      <td>92</td>\n",
       "      <td>57</td>\n",
       "      <td>71</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>男</td>\n",
       "      <td>7</td>\n",
       "      <td>129</td>\n",
       "      <td>54</td>\n",
       "      <td>25</td>\n",
       "      <td>80</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>男</td>\n",
       "      <td>6</td>\n",
       "      <td>37</td>\n",
       "      <td>100</td>\n",
       "      <td>6</td>\n",
       "      <td>140</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>男</td>\n",
       "      <td>3</td>\n",
       "      <td>50</td>\n",
       "      <td>9</td>\n",
       "      <td>81</td>\n",
       "      <td>63</td>\n",
       "      <td>64</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>270</th>\n",
       "      <td>男</td>\n",
       "      <td>2</td>\n",
       "      <td>47</td>\n",
       "      <td>93</td>\n",
       "      <td>145</td>\n",
       "      <td>103</td>\n",
       "      <td>101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>271</th>\n",
       "      <td>男</td>\n",
       "      <td>2</td>\n",
       "      <td>95</td>\n",
       "      <td>118</td>\n",
       "      <td>21</td>\n",
       "      <td>133</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>272</th>\n",
       "      <td>⼥</td>\n",
       "      <td>3</td>\n",
       "      <td>100</td>\n",
       "      <td>53</td>\n",
       "      <td>71</td>\n",
       "      <td>93</td>\n",
       "      <td>119</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>273</th>\n",
       "      <td>⼥</td>\n",
       "      <td>6</td>\n",
       "      <td>39</td>\n",
       "      <td>27</td>\n",
       "      <td>115</td>\n",
       "      <td>46</td>\n",
       "      <td>133</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>274</th>\n",
       "      <td>男</td>\n",
       "      <td>8</td>\n",
       "      <td>128</td>\n",
       "      <td>109</td>\n",
       "      <td>46</td>\n",
       "      <td>12</td>\n",
       "      <td>124</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>275</th>\n",
       "      <td>⼥</td>\n",
       "      <td>3</td>\n",
       "      <td>130</td>\n",
       "      <td>78</td>\n",
       "      <td>116</td>\n",
       "      <td>34</td>\n",
       "      <td>109</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>276</th>\n",
       "      <td>⼥</td>\n",
       "      <td>3</td>\n",
       "      <td>133</td>\n",
       "      <td>98</td>\n",
       "      <td>58</td>\n",
       "      <td>121</td>\n",
       "      <td>25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>277</th>\n",
       "      <td>⼥</td>\n",
       "      <td>5</td>\n",
       "      <td>126</td>\n",
       "      <td>138</td>\n",
       "      <td>113</td>\n",
       "      <td>42</td>\n",
       "      <td>63</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>278</th>\n",
       "      <td>男</td>\n",
       "      <td>5</td>\n",
       "      <td>94</td>\n",
       "      <td>46</td>\n",
       "      <td>50</td>\n",
       "      <td>74</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>279</th>\n",
       "      <td>⼥</td>\n",
       "      <td>7</td>\n",
       "      <td>23</td>\n",
       "      <td>1</td>\n",
       "      <td>125</td>\n",
       "      <td>67</td>\n",
       "      <td>130</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>280</th>\n",
       "      <td>男</td>\n",
       "      <td>3</td>\n",
       "      <td>45</td>\n",
       "      <td>15</td>\n",
       "      <td>70</td>\n",
       "      <td>103</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>281</th>\n",
       "      <td>⼥</td>\n",
       "      <td>3</td>\n",
       "      <td>38</td>\n",
       "      <td>32</td>\n",
       "      <td>98</td>\n",
       "      <td>77</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>282</th>\n",
       "      <td>⼥</td>\n",
       "      <td>2</td>\n",
       "      <td>144</td>\n",
       "      <td>111</td>\n",
       "      <td>9</td>\n",
       "      <td>115</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>283</th>\n",
       "      <td>男</td>\n",
       "      <td>3</td>\n",
       "      <td>70</td>\n",
       "      <td>123</td>\n",
       "      <td>36</td>\n",
       "      <td>58</td>\n",
       "      <td>59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>284</th>\n",
       "      <td>男</td>\n",
       "      <td>3</td>\n",
       "      <td>33</td>\n",
       "      <td>27</td>\n",
       "      <td>93</td>\n",
       "      <td>95</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>285</th>\n",
       "      <td>男</td>\n",
       "      <td>8</td>\n",
       "      <td>121</td>\n",
       "      <td>24</td>\n",
       "      <td>112</td>\n",
       "      <td>113</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>286</th>\n",
       "      <td>⼥</td>\n",
       "      <td>8</td>\n",
       "      <td>134</td>\n",
       "      <td>88</td>\n",
       "      <td>117</td>\n",
       "      <td>90</td>\n",
       "      <td>32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>287</th>\n",
       "      <td>男</td>\n",
       "      <td>4</td>\n",
       "      <td>34</td>\n",
       "      <td>49</td>\n",
       "      <td>42</td>\n",
       "      <td>34</td>\n",
       "      <td>142</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>288</th>\n",
       "      <td>男</td>\n",
       "      <td>8</td>\n",
       "      <td>59</td>\n",
       "      <td>118</td>\n",
       "      <td>63</td>\n",
       "      <td>92</td>\n",
       "      <td>114</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>289</th>\n",
       "      <td>⼥</td>\n",
       "      <td>1</td>\n",
       "      <td>122</td>\n",
       "      <td>42</td>\n",
       "      <td>16</td>\n",
       "      <td>108</td>\n",
       "      <td>105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>290</th>\n",
       "      <td>⼥</td>\n",
       "      <td>7</td>\n",
       "      <td>6</td>\n",
       "      <td>22</td>\n",
       "      <td>79</td>\n",
       "      <td>96</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>291</th>\n",
       "      <td>⼥</td>\n",
       "      <td>1</td>\n",
       "      <td>114</td>\n",
       "      <td>12</td>\n",
       "      <td>63</td>\n",
       "      <td>63</td>\n",
       "      <td>79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>292</th>\n",
       "      <td>⼥</td>\n",
       "      <td>4</td>\n",
       "      <td>112</td>\n",
       "      <td>66</td>\n",
       "      <td>62</td>\n",
       "      <td>30</td>\n",
       "      <td>131</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>293</th>\n",
       "      <td>⼥</td>\n",
       "      <td>8</td>\n",
       "      <td>138</td>\n",
       "      <td>59</td>\n",
       "      <td>51</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>294</th>\n",
       "      <td>男</td>\n",
       "      <td>1</td>\n",
       "      <td>149</td>\n",
       "      <td>147</td>\n",
       "      <td>38</td>\n",
       "      <td>57</td>\n",
       "      <td>121</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>295</th>\n",
       "      <td>⼥</td>\n",
       "      <td>4</td>\n",
       "      <td>142</td>\n",
       "      <td>52</td>\n",
       "      <td>120</td>\n",
       "      <td>59</td>\n",
       "      <td>149</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>296</th>\n",
       "      <td>男</td>\n",
       "      <td>1</td>\n",
       "      <td>85</td>\n",
       "      <td>104</td>\n",
       "      <td>11</td>\n",
       "      <td>91</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>297</th>\n",
       "      <td>男</td>\n",
       "      <td>6</td>\n",
       "      <td>86</td>\n",
       "      <td>74</td>\n",
       "      <td>83</td>\n",
       "      <td>137</td>\n",
       "      <td>101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>298</th>\n",
       "      <td>⼥</td>\n",
       "      <td>6</td>\n",
       "      <td>139</td>\n",
       "      <td>27</td>\n",
       "      <td>56</td>\n",
       "      <td>144</td>\n",
       "      <td>117</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>299</th>\n",
       "      <td>男</td>\n",
       "      <td>6</td>\n",
       "      <td>81</td>\n",
       "      <td>141</td>\n",
       "      <td>124</td>\n",
       "      <td>54</td>\n",
       "      <td>86</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>300 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    sex  class  Python  Keras  Tensorflow  Java  C++\n",
       "0     男      1     114    150          87     3  149\n",
       "1     男      7     134    150          36     8   57\n",
       "2     男      1     123     87         117    50   87\n",
       "3     ⼥      3      77     84          75    15   55\n",
       "4     ⼥      1      19      1          56    16  109\n",
       "5     男      8      59    101         126   149   78\n",
       "6     男      6      43     88         107    79   45\n",
       "7     ⼥      8      46     40          82   115   99\n",
       "8     男      8     103      7          81    79  105\n",
       "9     男      3     137     89          36    38  118\n",
       "10    ⼥      4       4    110         130   150   46\n",
       "11    男      7       2     26          57   106  102\n",
       "12    男      5      18    141           2    81   88\n",
       "13    ⼥      4     102     21         103    24   72\n",
       "14    ⼥      4      48     94          22    61  147\n",
       "15    ⼥      4      23     97          58    82  139\n",
       "16    男      4      21    116          17   114   84\n",
       "17    男      2      62    135         108   123  134\n",
       "18    男      3       8     90         110     7   89\n",
       "19    男      7     145    145         106    42   80\n",
       "20    男      8     114     54          11    17   55\n",
       "21    男      3     110     47         142   143   22\n",
       "22    ⼥      3      47    119          76    93   91\n",
       "23    ⼥      8      88     31          68   132   22\n",
       "24    男      5      99     95          82     1    0\n",
       "25    男      5     108    119          77   105  115\n",
       "26    男      6      14     92          57    71   17\n",
       "27    男      7     129     54          25    80   11\n",
       "28    男      6      37    100           6   140   89\n",
       "29    男      3      50      9          81    63   64\n",
       "..   ..    ...     ...    ...         ...   ...  ...\n",
       "270   男      2      47     93         145   103  101\n",
       "271   男      2      95    118          21   133   42\n",
       "272   ⼥      3     100     53          71    93  119\n",
       "273   ⼥      6      39     27         115    46  133\n",
       "274   男      8     128    109          46    12  124\n",
       "275   ⼥      3     130     78         116    34  109\n",
       "276   ⼥      3     133     98          58   121   25\n",
       "277   ⼥      5     126    138         113    42   63\n",
       "278   男      5      94     46          50    74   22\n",
       "279   ⼥      7      23      1         125    67  130\n",
       "280   男      3      45     15          70   103   26\n",
       "281   ⼥      3      38     32          98    77   43\n",
       "282   ⼥      2     144    111           9   115   14\n",
       "283   男      3      70    123          36    58   59\n",
       "284   男      3      33     27          93    95   76\n",
       "285   男      8     121     24         112   113   42\n",
       "286   ⼥      8     134     88         117    90   32\n",
       "287   男      4      34     49          42    34  142\n",
       "288   男      8      59    118          63    92  114\n",
       "289   ⼥      1     122     42          16   108  105\n",
       "290   ⼥      7       6     22          79    96   23\n",
       "291   ⼥      1     114     12          63    63   79\n",
       "292   ⼥      4     112     66          62    30  131\n",
       "293   ⼥      8     138     59          51     6    0\n",
       "294   男      1     149    147          38    57  121\n",
       "295   ⼥      4     142     52         120    59  149\n",
       "296   男      1      85    104          11    91    7\n",
       "297   男      6      86     74          83   137  101\n",
       "298   ⼥      6     139     27          56   144  117\n",
       "299   男      6      81    141         124    54   86\n",
       "\n",
       "[300 rows x 7 columns]"
      ]
     },
     "execution_count": 256,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 准备数据\n",
    "df = pd.DataFrame(data = {'sex':np.random.randint(0,2,size = 300), # 0男，1⼥\n",
    " 'class':np.random.randint(1,9,size = 300),#1~8⼋个班\n",
    " 'Python':np.random.randint(0,151,size = 300),#Python成绩\n",
    " 'Keras':np.random.randint(0,151,size =300),#Keras成绩\n",
    " 'Tensorflow':np.random.randint(0,151,size=300),\n",
    " 'Java':np.random.randint(0,151,size = 300),\n",
    " 'C++':np.random.randint(0,151,size = 300)})\n",
    "df['sex'] = df['sex'].map({0:'男',1:'⼥'}) # 将0，1映射成男⼥\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 264,
   "id": "looking-strap",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "组名： ⼥\n",
      "数据：     sex  class  Python  Keras  Tensorflow  Java  C++\n",
      "3     ⼥      3      77     84          75    15   55\n",
      "4     ⼥      1      19      1          56    16  109\n",
      "7     ⼥      8      46     40          82   115   99\n",
      "10    ⼥      4       4    110         130   150   46\n",
      "13    ⼥      4     102     21         103    24   72\n",
      "14    ⼥      4      48     94          22    61  147\n",
      "15    ⼥      4      23     97          58    82  139\n",
      "22    ⼥      3      47    119          76    93   91\n",
      "23    ⼥      8      88     31          68   132   22\n",
      "34    ⼥      8      25    110          63    99   86\n",
      "36    ⼥      3     118     68          89    39   89\n",
      "37    ⼥      7     121     56          96   123  106\n",
      "39    ⼥      4     125     42         109   126   84\n",
      "40    ⼥      4      32     55          27    60   88\n",
      "42    ⼥      6      79     70          86    12  137\n",
      "44    ⼥      2      29     21          16    24  150\n",
      "46    ⼥      4      51    132          55    92   42\n",
      "47    ⼥      4      97     49         109   140  123\n",
      "52    ⼥      5     132    104         106    97  134\n",
      "54    ⼥      8      22     88          47     0   49\n",
      "55    ⼥      6      79     61          97   117   26\n",
      "59    ⼥      8     146     25          19     5  107\n",
      "64    ⼥      7      30    150          29    90  121\n",
      "65    ⼥      4      89     94           5    77    4\n",
      "67    ⼥      3      12     17          17    37  116\n",
      "68    ⼥      5      71     68          96    79  148\n",
      "71    ⼥      2     117     42          69    72    0\n",
      "74    ⼥      8      19     83           1    14  126\n",
      "77    ⼥      5     102     72         125    56  136\n",
      "78    ⼥      7      87    112         126    80    4\n",
      "..   ..    ...     ...    ...         ...   ...  ...\n",
      "251   ⼥      5      24    113          40    21  129\n",
      "253   ⼥      7      66    122         105   131   48\n",
      "254   ⼥      5       0     86          64   118   44\n",
      "256   ⼥      4      53     82          65   113   70\n",
      "257   ⼥      3     125    121          58    19   40\n",
      "258   ⼥      3      60     94          63    90  130\n",
      "260   ⼥      1      51     89         132   100   25\n",
      "261   ⼥      3     149     97           0    96   38\n",
      "263   ⼥      3      69     69         142    49  150\n",
      "264   ⼥      1      57    121         108   130   58\n",
      "265   ⼥      1     138     61          92    95   56\n",
      "266   ⼥      8     133      8          20   110   65\n",
      "267   ⼥      2      44     96         121    82    6\n",
      "268   ⼥      6      49     37          53    66  150\n",
      "272   ⼥      3     100     53          71    93  119\n",
      "273   ⼥      6      39     27         115    46  133\n",
      "275   ⼥      3     130     78         116    34  109\n",
      "276   ⼥      3     133     98          58   121   25\n",
      "277   ⼥      5     126    138         113    42   63\n",
      "279   ⼥      7      23      1         125    67  130\n",
      "281   ⼥      3      38     32          98    77   43\n",
      "282   ⼥      2     144    111           9   115   14\n",
      "286   ⼥      8     134     88         117    90   32\n",
      "289   ⼥      1     122     42          16   108  105\n",
      "290   ⼥      7       6     22          79    96   23\n",
      "291   ⼥      1     114     12          63    63   79\n",
      "292   ⼥      4     112     66          62    30  131\n",
      "293   ⼥      8     138     59          51     6    0\n",
      "295   ⼥      4     142     52         120    59  149\n",
      "298   ⼥      6     139     27          56   144  117\n",
      "\n",
      "[148 rows x 7 columns]\n",
      "组名： 男\n",
      "数据：     sex  class  Python  Keras  Tensorflow  Java  C++\n",
      "0     男      1     114    150          87     3  149\n",
      "1     男      7     134    150          36     8   57\n",
      "2     男      1     123     87         117    50   87\n",
      "5     男      8      59    101         126   149   78\n",
      "6     男      6      43     88         107    79   45\n",
      "8     男      8     103      7          81    79  105\n",
      "9     男      3     137     89          36    38  118\n",
      "11    男      7       2     26          57   106  102\n",
      "12    男      5      18    141           2    81   88\n",
      "16    男      4      21    116          17   114   84\n",
      "17    男      2      62    135         108   123  134\n",
      "18    男      3       8     90         110     7   89\n",
      "19    男      7     145    145         106    42   80\n",
      "20    男      8     114     54          11    17   55\n",
      "21    男      3     110     47         142   143   22\n",
      "24    男      5      99     95          82     1    0\n",
      "25    男      5     108    119          77   105  115\n",
      "26    男      6      14     92          57    71   17\n",
      "27    男      7     129     54          25    80   11\n",
      "28    男      6      37    100           6   140   89\n",
      "29    男      3      50      9          81    63   64\n",
      "30    男      6      23     22         118   105  103\n",
      "31    男      3      45     51         145    23   80\n",
      "32    男      7     146     12          34    36   96\n",
      "33    男      1      75    119           7    29   94\n",
      "35    男      1     124     89          19    77  110\n",
      "38    男      7     137     75          30    26  109\n",
      "41    男      1       8     16         148    56   27\n",
      "43    男      4     135    145          72    31   57\n",
      "45    男      1      40     62          95    58  114\n",
      "..   ..    ...     ...    ...         ...   ...  ...\n",
      "233   男      6      69     99          69    48    5\n",
      "234   男      8      43    130          97   139   33\n",
      "235   男      2     129     29         117    55  131\n",
      "237   男      5      30     66          69     1   74\n",
      "238   男      4     117     16         119    78   91\n",
      "241   男      7       2     13          40    48  101\n",
      "242   男      4      10    120          65     9  143\n",
      "244   男      2      52    141         142    65  131\n",
      "245   男      5     137     78          76    67   10\n",
      "247   男      5       2    101          95   142    7\n",
      "248   男      1      29    148          58   145  113\n",
      "252   男      4     126    121         123    85  107\n",
      "255   男      1      83     50          35    57  106\n",
      "259   男      2      56      7          98   143    3\n",
      "262   男      5     126     18         133     1   46\n",
      "269   男      5      86    110          29    82   86\n",
      "270   男      2      47     93         145   103  101\n",
      "271   男      2      95    118          21   133   42\n",
      "274   男      8     128    109          46    12  124\n",
      "278   男      5      94     46          50    74   22\n",
      "280   男      3      45     15          70   103   26\n",
      "283   男      3      70    123          36    58   59\n",
      "284   男      3      33     27          93    95   76\n",
      "285   男      8     121     24         112   113   42\n",
      "287   男      4      34     49          42    34  142\n",
      "288   男      8      59    118          63    92  114\n",
      "294   男      1     149    147          38    57  121\n",
      "296   男      1      85    104          11    91    7\n",
      "297   男      6      86     74          83   137  101\n",
      "299   男      6      81    141         124    54   86\n",
      "\n",
      "[152 rows x 7 columns]\n"
     ]
    }
   ],
   "source": [
    "# 1、分组->可迭代对象\n",
    "# 1.1 先分组再获取数据\n",
    "g1 = df.groupby(by = 'sex')[['Python','Java']] # 单分组----只根据性别进行分组\n",
    "for name,data in g1:\n",
    "    print('组名：',name)\n",
    "    print('数据：',data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 261,
   "id": "boolean-motel",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "组名： (1, '⼥')\n",
      "数据：     sex  class  Python  Keras  Tensorflow  Java  C++\n",
      "4     ⼥      1      19      1          56    16  109\n",
      "89    ⼥      1     145     57         146    73  145\n",
      "102   ⼥      1      37     21           4    65   66\n",
      "106   ⼥      1      77    124          11   127   70\n",
      "118   ⼥      1      44    105          93    25  121\n",
      "126   ⼥      1     141     67         116    30  104\n",
      "138   ⼥      1      59    146          96    51   68\n",
      "149   ⼥      1     109     31         106    43   65\n",
      "165   ⼥      1      43     56          30    17  124\n",
      "196   ⼥      1      47      4         115   138   34\n",
      "210   ⼥      1      23     58          24    32  150\n",
      "227   ⼥      1     133    131         105   133  149\n",
      "229   ⼥      1       7     36          24    34  129\n",
      "230   ⼥      1     124     80         137    69   16\n",
      "236   ⼥      1      78     23          94    18  135\n",
      "250   ⼥      1      63     19         105    30   44\n",
      "260   ⼥      1      51     89         132   100   25\n",
      "264   ⼥      1      57    121         108   130   58\n",
      "265   ⼥      1     138     61          92    95   56\n",
      "289   ⼥      1     122     42          16   108  105\n",
      "291   ⼥      1     114     12          63    63   79\n",
      "组名： (1, '男')\n",
      "数据：     sex  class  Python  Keras  Tensorflow  Java  C++\n",
      "0     男      1     114    150          87     3  149\n",
      "2     男      1     123     87         117    50   87\n",
      "33    男      1      75    119           7    29   94\n",
      "35    男      1     124     89          19    77  110\n",
      "41    男      1       8     16         148    56   27\n",
      "45    男      1      40     62          95    58  114\n",
      "48    男      1      97    122          30     3   22\n",
      "49    男      1     117     60          87   149  144\n",
      "70    男      1      32     67         131   128   58\n",
      "73    男      1     130    139          55    72   85\n",
      "116   男      1      61     57          25    18  105\n",
      "130   男      1     100     72          59   142  104\n",
      "135   男      1      18     31         139    17   23\n",
      "139   男      1      12     20         126   131   13\n",
      "154   男      1      76     91          30   104   23\n",
      "163   男      1      18    131          18    19   98\n",
      "169   男      1      58     43         117    27  100\n",
      "170   男      1      65     37          22    67  121\n",
      "190   男      1      59    114          52   135   63\n",
      "193   男      1     103     17          41   118  122\n",
      "199   男      1      48     70          52   128   78\n",
      "216   男      1      12     68         122    15  108\n",
      "218   男      1     117     66         101    99  139\n",
      "225   男      1      92     34          25    61   93\n",
      "248   男      1      29    148          58   145  113\n",
      "255   男      1      83     50          35    57  106\n",
      "294   男      1     149    147          38    57  121\n",
      "296   男      1      85    104          11    91    7\n",
      "组名： (2, '⼥')\n",
      "数据：     sex  class  Python  Keras  Tensorflow  Java  C++\n",
      "44    ⼥      2      29     21          16    24  150\n",
      "71    ⼥      2     117     42          69    72    0\n",
      "81    ⼥      2      92     98          60    16   10\n",
      "85    ⼥      2      50    149          17    12  117\n",
      "87    ⼥      2     123    108          70    96   10\n",
      "109   ⼥      2     145     44         148    40   73\n",
      "112   ⼥      2      27     10         144    54  141\n",
      "123   ⼥      2      58     92          79    78  140\n",
      "129   ⼥      2      40     37          39    59   13\n",
      "131   ⼥      2     120    111          54   115   79\n",
      "142   ⼥      2     150    145          51    68  116\n",
      "194   ⼥      2      35     43         122   136   56\n",
      "202   ⼥      2      83     90         135    73   30\n",
      "208   ⼥      2      40     94           1   135   38\n",
      "232   ⼥      2      65    139         123     4  123\n",
      "243   ⼥      2      40     90          57    14   80\n",
      "249   ⼥      2      50    142          19   144   61\n",
      "267   ⼥      2      44     96         121    82    6\n",
      "282   ⼥      2     144    111           9   115   14\n",
      "组名： (2, '男')\n",
      "数据：     sex  class  Python  Keras  Tensorflow  Java  C++\n",
      "17    男      2      62    135         108   123  134\n",
      "63    男      2      73     82          38    48  116\n",
      "76    男      2      24     24          60     2  101\n",
      "96    男      2      42    100         113     8  149\n",
      "100   男      2      81    132          54   114  146\n",
      "141   男      2     141     45          57     5   79\n",
      "159   男      2     131    141          74   145  137\n",
      "171   男      2     100     81          74    96  143\n",
      "172   男      2      81    108          80   120   97\n",
      "205   男      2      18    128          55    28  106\n",
      "215   男      2     100     44         109    78   74\n",
      "235   男      2     129     29         117    55  131\n",
      "244   男      2      52    141         142    65  131\n",
      "259   男      2      56      7          98   143    3\n",
      "270   男      2      47     93         145   103  101\n",
      "271   男      2      95    118          21   133   42\n",
      "组名： (3, '⼥')\n",
      "数据：     sex  class  Python  Keras  Tensorflow  Java  C++\n",
      "3     ⼥      3      77     84          75    15   55\n",
      "22    ⼥      3      47    119          76    93   91\n",
      "36    ⼥      3     118     68          89    39   89\n",
      "67    ⼥      3      12     17          17    37  116\n",
      "105   ⼥      3     135    102          26   141   91\n",
      "122   ⼥      3     142    136          21    78   64\n",
      "128   ⼥      3     131     73          21    55   82\n",
      "143   ⼥      3      68     60           4    84  135\n",
      "168   ⼥      3      38    142         118    67   42\n",
      "186   ⼥      3     104     25          91   103  146\n",
      "206   ⼥      3       0     24         130    11  124\n",
      "213   ⼥      3     150     42           1   148  135\n",
      "214   ⼥      3      32    117          40    92   17\n",
      "257   ⼥      3     125    121          58    19   40\n",
      "258   ⼥      3      60     94          63    90  130\n",
      "261   ⼥      3     149     97           0    96   38\n",
      "263   ⼥      3      69     69         142    49  150\n",
      "272   ⼥      3     100     53          71    93  119\n",
      "275   ⼥      3     130     78         116    34  109\n",
      "276   ⼥      3     133     98          58   121   25\n",
      "281   ⼥      3      38     32          98    77   43\n",
      "组名： (3, '男')\n",
      "数据：     sex  class  Python  Keras  Tensorflow  Java  C++\n",
      "9     男      3     137     89          36    38  118\n",
      "18    男      3       8     90         110     7   89\n",
      "21    男      3     110     47         142   143   22\n",
      "29    男      3      50      9          81    63   64\n",
      "31    男      3      45     51         145    23   80\n",
      "51    男      3      71     95         105    17  108\n",
      "60    男      3      21      5          97   147  124\n",
      "83    男      3      33     28          90    91   52\n",
      "164   男      3      69     79          59   133   50\n",
      "178   男      3     109    123         105    77   28\n",
      "198   男      3     149    113          29    52   76\n",
      "280   男      3      45     15          70   103   26\n",
      "283   男      3      70    123          36    58   59\n",
      "284   男      3      33     27          93    95   76\n",
      "组名： (4, '⼥')\n",
      "数据：     sex  class  Python  Keras  Tensorflow  Java  C++\n",
      "10    ⼥      4       4    110         130   150   46\n",
      "13    ⼥      4     102     21         103    24   72\n",
      "14    ⼥      4      48     94          22    61  147\n",
      "15    ⼥      4      23     97          58    82  139\n",
      "39    ⼥      4     125     42         109   126   84\n",
      "40    ⼥      4      32     55          27    60   88\n",
      "46    ⼥      4      51    132          55    92   42\n",
      "47    ⼥      4      97     49         109   140  123\n",
      "65    ⼥      4      89     94           5    77    4\n",
      "107   ⼥      4      49     68          75   104   36\n",
      "132   ⼥      4       9      9          86    66   13\n",
      "136   ⼥      4      21     70         128    85   22\n",
      "174   ⼥      4      38     60         120    40   62\n",
      "188   ⼥      4     112    122         111    79   26\n",
      "209   ⼥      4      16     86          62     6  127\n",
      "256   ⼥      4      53     82          65   113   70\n",
      "292   ⼥      4     112     66          62    30  131\n",
      "295   ⼥      4     142     52         120    59  149\n",
      "组名： (4, '男')\n",
      "数据：     sex  class  Python  Keras  Tensorflow  Java  C++\n",
      "16    男      4      21    116          17   114   84\n",
      "43    男      4     135    145          72    31   57\n",
      "50    男      4     106     78           5    44  123\n",
      "58    男      4     127    140          38    88   44\n",
      "92    男      4     118    125         114    80   97\n",
      "95    男      4     104     94          70    15   70\n",
      "97    男      4      63     34          87    66  117\n",
      "110   男      4      89     51          30    81  126\n",
      "173   男      4     149     64          56   118    4\n",
      "175   男      4     116     44         136    92  122\n",
      "177   男      4      81      2          88    27    0\n",
      "182   男      4      32    120          80    18   91\n",
      "187   男      4     129     42          92    39  117\n",
      "201   男      4      79     68         108   113   18\n",
      "207   男      4      66     25          72   125   54\n",
      "228   男      4      61     14          11    66    5\n",
      "238   男      4     117     16         119    78   91\n",
      "242   男      4      10    120          65     9  143\n",
      "252   男      4     126    121         123    85  107\n",
      "287   男      4      34     49          42    34  142\n",
      "组名： (5, '⼥')\n",
      "数据：     sex  class  Python  Keras  Tensorflow  Java  C++\n",
      "52    ⼥      5     132    104         106    97  134\n",
      "68    ⼥      5      71     68          96    79  148\n",
      "77    ⼥      5     102     72         125    56  136\n",
      "82    ⼥      5     104    122          44     8   81\n",
      "114   ⼥      5      26    117          18    97   33\n",
      "152   ⼥      5      84    115           8    42  138\n",
      "158   ⼥      5      36    121         138    94   46\n",
      "167   ⼥      5      42     49          39   147   39\n",
      "181   ⼥      5      41     57          66   135    9\n",
      "217   ⼥      5      19      9          42   134   35\n",
      "251   ⼥      5      24    113          40    21  129\n",
      "254   ⼥      5       0     86          64   118   44\n",
      "277   ⼥      5     126    138         113    42   63\n",
      "组名： (5, '男')\n",
      "数据：     sex  class  Python  Keras  Tensorflow  Java  C++\n",
      "12    男      5      18    141           2    81   88\n",
      "24    男      5      99     95          82     1    0\n",
      "25    男      5     108    119          77   105  115\n",
      "53    男      5      14     17         146   142  140\n",
      "66    男      5      61      5          38   101   54\n",
      "79    男      5     107     61          59    39   59\n",
      "86    男      5     102     16          77   119   87\n",
      "115   男      5      25    124         138   136   75\n",
      "146   男      5      76     62         105    80   31\n",
      "156   男      5      44     17         108   139  150\n",
      "157   男      5      46    104         113    92   38\n",
      "176   男      5      53     13          11   148   75\n",
      "179   男      5      83      1          84    21  118\n",
      "180   男      5     126     43           5   104   63\n",
      "183   男      5      98     39          65   111  123\n",
      "191   男      5      62    146          31   129  131\n",
      "226   男      5     127     48          79    12   65\n",
      "237   男      5      30     66          69     1   74\n",
      "245   男      5     137     78          76    67   10\n",
      "247   男      5       2    101          95   142    7\n",
      "262   男      5     126     18         133     1   46\n",
      "269   男      5      86    110          29    82   86\n",
      "278   男      5      94     46          50    74   22\n",
      "组名： (6, '⼥')\n",
      "数据：     sex  class  Python  Keras  Tensorflow  Java  C++\n",
      "42    ⼥      6      79     70          86    12  137\n",
      "55    ⼥      6      79     61          97   117   26\n",
      "101   ⼥      6     107     78          89   110   56\n",
      "103   ⼥      6      58    135           5    49   33\n",
      "104   ⼥      6      67     73          79    14   14\n",
      "108   ⼥      6      49    116          12    77   18\n",
      "121   ⼥      6      28    125         115    87   45\n",
      "124   ⼥      6      42    135         118   149   91\n",
      "155   ⼥      6      89    130          70    15    0\n",
      "161   ⼥      6     126    145          39    39  150\n",
      "185   ⼥      6       9    101         100    90  102\n",
      "195   ⼥      6     138     42         102    94  120\n",
      "219   ⼥      6      45      5          70    69    1\n",
      "224   ⼥      6     129     63          48    99   62\n",
      "240   ⼥      6     110    134         102   147    2\n",
      "268   ⼥      6      49     37          53    66  150\n",
      "273   ⼥      6      39     27         115    46  133\n",
      "298   ⼥      6     139     27          56   144  117\n",
      "组名： (6, '男')\n",
      "数据：     sex  class  Python  Keras  Tensorflow  Java  C++\n",
      "6     男      6      43     88         107    79   45\n",
      "26    男      6      14     92          57    71   17\n",
      "28    男      6      37    100           6   140   89\n",
      "30    男      6      23     22         118   105  103\n",
      "57    男      6     100    102         113     4   12\n",
      "61    男      6     131    140          50    85   52\n",
      "93    男      6     140     38          78    67  144\n",
      "98    男      6      98     93          79    22  110\n",
      "111   男      6     120     49          41   150   19\n",
      "125   男      6      45    145          78    38   18\n",
      "133   男      6      38     59          11    18   57\n",
      "144   男      6      57    130          86    82   26\n",
      "148   男      6      80     58          25    16   88\n",
      "153   男      6     143    125          75    46   56\n",
      "160   男      6      15     11          37    63   73\n",
      "211   男      6     149      9          81    53   29\n",
      "233   男      6      69     99          69    48    5\n",
      "297   男      6      86     74          83   137  101\n",
      "299   男      6      81    141         124    54   86\n",
      "组名： (7, '⼥')\n",
      "数据：     sex  class  Python  Keras  Tensorflow  Java  C++\n",
      "37    ⼥      7     121     56          96   123  106\n",
      "64    ⼥      7      30    150          29    90  121\n",
      "78    ⼥      7      87    112         126    80    4\n",
      "84    ⼥      7     132     69           4    10   82\n",
      "88    ⼥      7      51    129         116    80   48\n",
      "90    ⼥      7      61     84          99   147   71\n",
      "94    ⼥      7      20     24          95    24   32\n",
      "119   ⼥      7      69     24          74    22   55\n",
      "140   ⼥      7     110     48           6     6  146\n",
      "147   ⼥      7      37     47         144    74   72\n",
      "162   ⼥      7     149     61          96   108   49\n",
      "192   ⼥      7      49     35          98    52   26\n",
      "203   ⼥      7      68     35         125   124   94\n",
      "221   ⼥      7     139     93         102    50    2\n",
      "239   ⼥      7      26     13          24   137   39\n",
      "253   ⼥      7      66    122         105   131   48\n",
      "279   ⼥      7      23      1         125    67  130\n",
      "290   ⼥      7       6     22          79    96   23\n",
      "组名： (7, '男')\n",
      "数据：     sex  class  Python  Keras  Tensorflow  Java  C++\n",
      "1     男      7     134    150          36     8   57\n",
      "11    男      7       2     26          57   106  102\n",
      "19    男      7     145    145         106    42   80\n",
      "27    男      7     129     54          25    80   11\n",
      "32    男      7     146     12          34    36   96\n",
      "38    男      7     137     75          30    26  109\n",
      "62    男      7      42    150          30     7    1\n",
      "91    男      7     125    119          32    85   44\n",
      "127   男      7      27     20         108     5  128\n",
      "137   男      7     147    107         149    15  140\n",
      "150   男      7     120     71          41    85  108\n",
      "189   男      7       9     94         122   136   31\n",
      "197   男      7       6    113          28     5   36\n",
      "200   男      7      53    146          71   116  110\n",
      "220   男      7     150    115          88    97  146\n",
      "241   男      7       2     13          40    48  101\n",
      "组名： (8, '⼥')\n",
      "数据：     sex  class  Python  Keras  Tensorflow  Java  C++\n",
      "7     ⼥      8      46     40          82   115   99\n",
      "23    ⼥      8      88     31          68   132   22\n",
      "34    ⼥      8      25    110          63    99   86\n",
      "54    ⼥      8      22     88          47     0   49\n",
      "59    ⼥      8     146     25          19     5  107\n",
      "74    ⼥      8      19     83           1    14  126\n",
      "80    ⼥      8      16    123          22    81   83\n",
      "99    ⼥      8      30    106          42    34  118\n",
      "113   ⼥      8     136     86          44    55   27\n",
      "120   ⼥      8      60    125          24   123    9\n",
      "134   ⼥      8      58     96         117    30   27\n",
      "166   ⼥      8      76     57          26   111   58\n",
      "184   ⼥      8      97     65          11    81   46\n",
      "204   ⼥      8      99    115          40    61  106\n",
      "222   ⼥      8     136    101         109    81   36\n",
      "231   ⼥      8      93     28         130    28   90\n",
      "246   ⼥      8      96     60          92   137   91\n",
      "266   ⼥      8     133      8          20   110   65\n",
      "286   ⼥      8     134     88         117    90   32\n",
      "293   ⼥      8     138     59          51     6    0\n",
      "组名： (8, '男')\n",
      "数据：     sex  class  Python  Keras  Tensorflow  Java  C++\n",
      "5     男      8      59    101         126   149   78\n",
      "8     男      8     103      7          81    79  105\n",
      "20    男      8     114     54          11    17   55\n",
      "56    男      8      45    130          35    17   98\n",
      "69    男      8      58     33         137   123   70\n",
      "72    男      8      64     14         114    29  122\n",
      "75    男      8      58     59          12   129   32\n",
      "117   男      8     136      5          18   122  126\n",
      "145   男      8      25     95           5    88  132\n",
      "151   男      8      59     32          83    86    1\n",
      "212   男      8      56    108         107    14   49\n",
      "223   男      8     102     46           4    64  137\n",
      "234   男      8      43    130          97   139   33\n",
      "274   男      8     128    109          46    12  124\n",
      "285   男      8     121     24         112   113   42\n",
      "288   男      8      59    118          63    92  114\n"
     ]
    }
   ],
   "source": [
    "g2 = df.groupby(by = ['class','sex'])[['Python']] # 多分组\n",
    "for name,data in g2:\n",
    "    print('组名：',name)\n",
    "    print('数据：',data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 271,
   "id": "stuck-student",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<pandas.core.groupby.generic.SeriesGroupBy object at 0x000002ACD5CC7860>"
      ]
     },
     "execution_count": 271,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#2.对一列值进行分组\n",
    "df['Python'].groupby(df['class'])#单分组\n",
    "df['Python'].groupby([df['class'],df['sex']])#多分组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 268,
   "id": "homeless-convention",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "int32\n",
      "     class  Python  Keras  Tensorflow  Java  C++\n",
      "0        1     114    150          87     3  149\n",
      "1        7     134    150          36     8   57\n",
      "2        1     123     87         117    50   87\n",
      "3        3      77     84          75    15   55\n",
      "4        1      19      1          56    16  109\n",
      "5        8      59    101         126   149   78\n",
      "6        6      43     88         107    79   45\n",
      "7        8      46     40          82   115   99\n",
      "8        8     103      7          81    79  105\n",
      "9        3     137     89          36    38  118\n",
      "10       4       4    110         130   150   46\n",
      "11       7       2     26          57   106  102\n",
      "12       5      18    141           2    81   88\n",
      "13       4     102     21         103    24   72\n",
      "14       4      48     94          22    61  147\n",
      "15       4      23     97          58    82  139\n",
      "16       4      21    116          17   114   84\n",
      "17       2      62    135         108   123  134\n",
      "18       3       8     90         110     7   89\n",
      "19       7     145    145         106    42   80\n",
      "20       8     114     54          11    17   55\n",
      "21       3     110     47         142   143   22\n",
      "22       3      47    119          76    93   91\n",
      "23       8      88     31          68   132   22\n",
      "24       5      99     95          82     1    0\n",
      "25       5     108    119          77   105  115\n",
      "26       6      14     92          57    71   17\n",
      "27       7     129     54          25    80   11\n",
      "28       6      37    100           6   140   89\n",
      "29       3      50      9          81    63   64\n",
      "..     ...     ...    ...         ...   ...  ...\n",
      "270      2      47     93         145   103  101\n",
      "271      2      95    118          21   133   42\n",
      "272      3     100     53          71    93  119\n",
      "273      6      39     27         115    46  133\n",
      "274      8     128    109          46    12  124\n",
      "275      3     130     78         116    34  109\n",
      "276      3     133     98          58   121   25\n",
      "277      5     126    138         113    42   63\n",
      "278      5      94     46          50    74   22\n",
      "279      7      23      1         125    67  130\n",
      "280      3      45     15          70   103   26\n",
      "281      3      38     32          98    77   43\n",
      "282      2     144    111           9   115   14\n",
      "283      3      70    123          36    58   59\n",
      "284      3      33     27          93    95   76\n",
      "285      8     121     24         112   113   42\n",
      "286      8     134     88         117    90   32\n",
      "287      4      34     49          42    34  142\n",
      "288      8      59    118          63    92  114\n",
      "289      1     122     42          16   108  105\n",
      "290      7       6     22          79    96   23\n",
      "291      1     114     12          63    63   79\n",
      "292      4     112     66          62    30  131\n",
      "293      8     138     59          51     6    0\n",
      "294      1     149    147          38    57  121\n",
      "295      4     142     52         120    59  149\n",
      "296      1      85    104          11    91    7\n",
      "297      6      86     74          83   137  101\n",
      "298      6     139     27          56   144  117\n",
      "299      6      81    141         124    54   86\n",
      "\n",
      "[300 rows x 6 columns]\n",
      "object\n",
      "    sex\n",
      "0     男\n",
      "1     男\n",
      "2     男\n",
      "3     ⼥\n",
      "4     ⼥\n",
      "5     男\n",
      "6     男\n",
      "7     ⼥\n",
      "8     男\n",
      "9     男\n",
      "10    ⼥\n",
      "11    男\n",
      "12    男\n",
      "13    ⼥\n",
      "14    ⼥\n",
      "15    ⼥\n",
      "16    男\n",
      "17    男\n",
      "18    男\n",
      "19    男\n",
      "20    男\n",
      "21    男\n",
      "22    ⼥\n",
      "23    ⼥\n",
      "24    男\n",
      "25    男\n",
      "26    男\n",
      "27    男\n",
      "28    男\n",
      "29    男\n",
      "..   ..\n",
      "270   男\n",
      "271   男\n",
      "272   ⼥\n",
      "273   ⼥\n",
      "274   男\n",
      "275   ⼥\n",
      "276   ⼥\n",
      "277   ⼥\n",
      "278   男\n",
      "279   ⼥\n",
      "280   男\n",
      "281   ⼥\n",
      "282   ⼥\n",
      "283   男\n",
      "284   男\n",
      "285   男\n",
      "286   ⼥\n",
      "287   男\n",
      "288   男\n",
      "289   ⼥\n",
      "290   ⼥\n",
      "291   ⼥\n",
      "292   ⼥\n",
      "293   ⼥\n",
      "294   男\n",
      "295   ⼥\n",
      "296   男\n",
      "297   男\n",
      "298   ⼥\n",
      "299   男\n",
      "\n",
      "[300 rows x 1 columns]\n"
     ]
    }
   ],
   "source": [
    "#3.根据数据类型进行分组\n",
    "for name,group in df.groupby(df.dtypes,axis=1):\n",
    "    print(name)\n",
    "    print(group)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 273,
   "id": "armed-smoke",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "组名 category\n",
      "数据     sex  class\n",
      "0     男      1\n",
      "1     男      7\n",
      "2     男      1\n",
      "3     ⼥      3\n",
      "4     ⼥      1\n",
      "5     男      8\n",
      "6     男      6\n",
      "7     ⼥      8\n",
      "8     男      8\n",
      "9     男      3\n",
      "10    ⼥      4\n",
      "11    男      7\n",
      "12    男      5\n",
      "13    ⼥      4\n",
      "14    ⼥      4\n",
      "15    ⼥      4\n",
      "16    男      4\n",
      "17    男      2\n",
      "18    男      3\n",
      "19    男      7\n",
      "20    男      8\n",
      "21    男      3\n",
      "22    ⼥      3\n",
      "23    ⼥      8\n",
      "24    男      5\n",
      "25    男      5\n",
      "26    男      6\n",
      "27    男      7\n",
      "28    男      6\n",
      "29    男      3\n",
      "..   ..    ...\n",
      "270   男      2\n",
      "271   男      2\n",
      "272   ⼥      3\n",
      "273   ⼥      6\n",
      "274   男      8\n",
      "275   ⼥      3\n",
      "276   ⼥      3\n",
      "277   ⼥      5\n",
      "278   男      5\n",
      "279   ⼥      7\n",
      "280   男      3\n",
      "281   ⼥      3\n",
      "282   ⼥      2\n",
      "283   男      3\n",
      "284   男      3\n",
      "285   男      8\n",
      "286   ⼥      8\n",
      "287   男      4\n",
      "288   男      8\n",
      "289   ⼥      1\n",
      "290   ⼥      7\n",
      "291   ⼥      1\n",
      "292   ⼥      4\n",
      "293   ⼥      8\n",
      "294   男      1\n",
      "295   ⼥      4\n",
      "296   男      1\n",
      "297   男      6\n",
      "298   ⼥      6\n",
      "299   男      6\n",
      "\n",
      "[300 rows x 2 columns]\n",
      "组名 科目\n",
      "数据      Python  Keras  Tensorflow  Java  C++\n",
      "0       114    150          87     3  149\n",
      "1       134    150          36     8   57\n",
      "2       123     87         117    50   87\n",
      "3        77     84          75    15   55\n",
      "4        19      1          56    16  109\n",
      "5        59    101         126   149   78\n",
      "6        43     88         107    79   45\n",
      "7        46     40          82   115   99\n",
      "8       103      7          81    79  105\n",
      "9       137     89          36    38  118\n",
      "10        4    110         130   150   46\n",
      "11        2     26          57   106  102\n",
      "12       18    141           2    81   88\n",
      "13      102     21         103    24   72\n",
      "14       48     94          22    61  147\n",
      "15       23     97          58    82  139\n",
      "16       21    116          17   114   84\n",
      "17       62    135         108   123  134\n",
      "18        8     90         110     7   89\n",
      "19      145    145         106    42   80\n",
      "20      114     54          11    17   55\n",
      "21      110     47         142   143   22\n",
      "22       47    119          76    93   91\n",
      "23       88     31          68   132   22\n",
      "24       99     95          82     1    0\n",
      "25      108    119          77   105  115\n",
      "26       14     92          57    71   17\n",
      "27      129     54          25    80   11\n",
      "28       37    100           6   140   89\n",
      "29       50      9          81    63   64\n",
      "..      ...    ...         ...   ...  ...\n",
      "270      47     93         145   103  101\n",
      "271      95    118          21   133   42\n",
      "272     100     53          71    93  119\n",
      "273      39     27         115    46  133\n",
      "274     128    109          46    12  124\n",
      "275     130     78         116    34  109\n",
      "276     133     98          58   121   25\n",
      "277     126    138         113    42   63\n",
      "278      94     46          50    74   22\n",
      "279      23      1         125    67  130\n",
      "280      45     15          70   103   26\n",
      "281      38     32          98    77   43\n",
      "282     144    111           9   115   14\n",
      "283      70    123          36    58   59\n",
      "284      33     27          93    95   76\n",
      "285     121     24         112   113   42\n",
      "286     134     88         117    90   32\n",
      "287      34     49          42    34  142\n",
      "288      59    118          63    92  114\n",
      "289     122     42          16   108  105\n",
      "290       6     22          79    96   23\n",
      "291     114     12          63    63   79\n",
      "292     112     66          62    30  131\n",
      "293     138     59          51     6    0\n",
      "294     149    147          38    57  121\n",
      "295     142     52         120    59  149\n",
      "296      85    104          11    91    7\n",
      "297      86     74          83   137  101\n",
      "298     139     27          56   144  117\n",
      "299      81    141         124    54   86\n",
      "\n",
      "[300 rows x 5 columns]\n"
     ]
    }
   ],
   "source": [
    "# 1.4 通过字典进⾏分组\n",
    "m ={'sex':'category','class':'category','Python':'科目','Keras':'科目','Tensorflow':'科目','Java':'科目','C++':'科目'}\n",
    "for name,data in df.groupby(m,axis = 1):\n",
    "    print('组名',name)\n",
    "    print('数据',data)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "monetary-personal",
   "metadata": {},
   "source": [
    "### 聚合"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 276,
   "id": "floppy-chinese",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>class</th>\n",
       "      <th>Python</th>\n",
       "      <th>Keras</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Java</th>\n",
       "      <th>C++</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sex</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>⼥</th>\n",
       "      <td>8</td>\n",
       "      <td>150</td>\n",
       "      <td>150</td>\n",
       "      <td>148</td>\n",
       "      <td>150</td>\n",
       "      <td>150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>男</th>\n",
       "      <td>8</td>\n",
       "      <td>150</td>\n",
       "      <td>150</td>\n",
       "      <td>149</td>\n",
       "      <td>150</td>\n",
       "      <td>150</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     class  Python  Keras  Tensorflow  Java  C++\n",
       "sex                                             \n",
       "⼥        8     150    150         148   150  150\n",
       "男        8     150    150         149   150  150"
      ]
     },
     "execution_count": 276,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.groupby(by ='sex').max() # 对所有列根据性别进行分组求各组最大"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 277,
   "id": "every-enemy",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Java</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sex</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>⼥</th>\n",
       "      <td>150</td>\n",
       "      <td>150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>男</th>\n",
       "      <td>150</td>\n",
       "      <td>150</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     Python  Java\n",
       "sex              \n",
       "⼥       150   150\n",
       "男       150   150"
      ]
     },
     "execution_count": 277,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.groupby(by ='sex')[['Python','Java']].max() #只对python和java分组求最大"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 278,
   "id": "following-singer",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Keras</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Java</th>\n",
       "      <th>C++</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sex</th>\n",
       "      <th>class</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"8\" valign=\"top\">⼥</th>\n",
       "      <th>1</th>\n",
       "      <td>78.0</td>\n",
       "      <td>61.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>67.0</td>\n",
       "      <td>88.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>76.0</td>\n",
       "      <td>87.0</td>\n",
       "      <td>70.0</td>\n",
       "      <td>70.0</td>\n",
       "      <td>66.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>88.0</td>\n",
       "      <td>79.0</td>\n",
       "      <td>63.0</td>\n",
       "      <td>73.0</td>\n",
       "      <td>88.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>62.0</td>\n",
       "      <td>73.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>77.0</td>\n",
       "      <td>77.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>62.0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>69.0</td>\n",
       "      <td>82.0</td>\n",
       "      <td>80.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>77.0</td>\n",
       "      <td>84.0</td>\n",
       "      <td>75.0</td>\n",
       "      <td>79.0</td>\n",
       "      <td>70.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>69.0</td>\n",
       "      <td>62.0</td>\n",
       "      <td>86.0</td>\n",
       "      <td>79.0</td>\n",
       "      <td>64.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>82.0</td>\n",
       "      <td>75.0</td>\n",
       "      <td>56.0</td>\n",
       "      <td>70.0</td>\n",
       "      <td>64.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"8\" valign=\"top\">男</th>\n",
       "      <th>1</th>\n",
       "      <td>73.0</td>\n",
       "      <td>79.0</td>\n",
       "      <td>66.0</td>\n",
       "      <td>73.0</td>\n",
       "      <td>87.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>77.0</td>\n",
       "      <td>88.0</td>\n",
       "      <td>84.0</td>\n",
       "      <td>79.0</td>\n",
       "      <td>106.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>68.0</td>\n",
       "      <td>64.0</td>\n",
       "      <td>86.0</td>\n",
       "      <td>75.0</td>\n",
       "      <td>69.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>88.0</td>\n",
       "      <td>73.0</td>\n",
       "      <td>71.0</td>\n",
       "      <td>66.0</td>\n",
       "      <td>81.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>75.0</td>\n",
       "      <td>64.0</td>\n",
       "      <td>73.0</td>\n",
       "      <td>84.0</td>\n",
       "      <td>72.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>77.0</td>\n",
       "      <td>83.0</td>\n",
       "      <td>69.0</td>\n",
       "      <td>67.0</td>\n",
       "      <td>59.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>86.0</td>\n",
       "      <td>88.0</td>\n",
       "      <td>62.0</td>\n",
       "      <td>56.0</td>\n",
       "      <td>81.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>77.0</td>\n",
       "      <td>67.0</td>\n",
       "      <td>66.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>82.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           Python  Keras  Tensorflow  Java    C++\n",
       "sex class                                        \n",
       "⼥   1        78.0   61.0        80.0  67.0   88.0\n",
       "    2        76.0   87.0        70.0  70.0   66.0\n",
       "    3        88.0   79.0        63.0  73.0   88.0\n",
       "    4        62.0   73.0        80.0  77.0   77.0\n",
       "    5        62.0   90.0        69.0  82.0   80.0\n",
       "    6        77.0   84.0        75.0  79.0   70.0\n",
       "    7        69.0   62.0        86.0  79.0   64.0\n",
       "    8        82.0   75.0        56.0  70.0   64.0\n",
       "男   1        73.0   79.0        66.0  73.0   87.0\n",
       "    2        77.0   88.0        84.0  79.0  106.0\n",
       "    3        68.0   64.0        86.0  75.0   69.0\n",
       "    4        88.0   73.0        71.0  66.0   81.0\n",
       "    5        75.0   64.0        73.0  84.0   72.0\n",
       "    6        77.0   83.0        69.0  67.0   59.0\n",
       "    7        86.0   88.0        62.0  56.0   81.0\n",
       "    8        77.0   67.0        66.0  80.0   82.0"
      ]
     },
     "execution_count": 278,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.groupby(by =['sex','class']).mean().round()#对性别和班级分组  ---多组划分求平均值"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "critical-fence",
   "metadata": {},
   "source": [
    "### 分组聚合-apply/transform的区别--但只能计算一种方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 280,
   "id": "falling-purpose",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Java</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sex</th>\n",
       "      <th>class</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"8\" valign=\"top\">⼥</th>\n",
       "      <th>1</th>\n",
       "      <td>77.7</td>\n",
       "      <td>66.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>76.4</td>\n",
       "      <td>70.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>88.5</td>\n",
       "      <td>73.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>62.4</td>\n",
       "      <td>77.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>62.1</td>\n",
       "      <td>82.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>76.8</td>\n",
       "      <td>79.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>69.1</td>\n",
       "      <td>78.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>82.4</td>\n",
       "      <td>69.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"8\" valign=\"top\">男</th>\n",
       "      <th>1</th>\n",
       "      <td>73.0</td>\n",
       "      <td>73.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>77.0</td>\n",
       "      <td>79.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>67.9</td>\n",
       "      <td>74.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>88.2</td>\n",
       "      <td>66.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>75.0</td>\n",
       "      <td>83.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>77.3</td>\n",
       "      <td>67.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>85.9</td>\n",
       "      <td>56.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>76.9</td>\n",
       "      <td>79.6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           Python  Java\n",
       "sex class              \n",
       "⼥   1        77.7  66.5\n",
       "    2        76.4  70.4\n",
       "    3        88.5  73.4\n",
       "    4        62.4  77.4\n",
       "    5        62.1  82.3\n",
       "    6        76.8  79.1\n",
       "    7        69.1  78.9\n",
       "    8        82.4  69.6\n",
       "男   1        73.0  73.4\n",
       "    2        77.0  79.1\n",
       "    3        67.9  74.8\n",
       "    4        88.2  66.2\n",
       "    5        75.0  83.8\n",
       "    6        77.3  67.3\n",
       "    7        85.9  56.1\n",
       "    8        76.9  79.6"
      ]
     },
     "execution_count": 280,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#apply是聚合结果，行数会变少\n",
    "df.groupby(by = ['sex','class'])[['Python','Java']].apply(np.mean).round(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 285,
   "id": "fatty-geometry",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Java</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>73.0</td>\n",
       "      <td>73.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>85.9</td>\n",
       "      <td>56.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>73.0</td>\n",
       "      <td>73.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>88.5</td>\n",
       "      <td>73.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>77.7</td>\n",
       "      <td>66.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>76.9</td>\n",
       "      <td>79.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>77.3</td>\n",
       "      <td>67.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>82.4</td>\n",
       "      <td>69.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>76.9</td>\n",
       "      <td>79.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>67.9</td>\n",
       "      <td>74.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>62.4</td>\n",
       "      <td>77.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>85.9</td>\n",
       "      <td>56.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>75.0</td>\n",
       "      <td>83.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>62.4</td>\n",
       "      <td>77.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>62.4</td>\n",
       "      <td>77.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>62.4</td>\n",
       "      <td>77.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>88.2</td>\n",
       "      <td>66.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>77.0</td>\n",
       "      <td>79.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>67.9</td>\n",
       "      <td>74.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>85.9</td>\n",
       "      <td>56.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>76.9</td>\n",
       "      <td>79.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>67.9</td>\n",
       "      <td>74.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>88.5</td>\n",
       "      <td>73.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>82.4</td>\n",
       "      <td>69.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>75.0</td>\n",
       "      <td>83.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>75.0</td>\n",
       "      <td>83.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>77.3</td>\n",
       "      <td>67.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>85.9</td>\n",
       "      <td>56.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>77.3</td>\n",
       "      <td>67.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>67.9</td>\n",
       "      <td>74.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>270</th>\n",
       "      <td>77.0</td>\n",
       "      <td>79.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>271</th>\n",
       "      <td>77.0</td>\n",
       "      <td>79.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>272</th>\n",
       "      <td>88.5</td>\n",
       "      <td>73.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>273</th>\n",
       "      <td>76.8</td>\n",
       "      <td>79.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>274</th>\n",
       "      <td>76.9</td>\n",
       "      <td>79.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>275</th>\n",
       "      <td>88.5</td>\n",
       "      <td>73.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>276</th>\n",
       "      <td>88.5</td>\n",
       "      <td>73.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>277</th>\n",
       "      <td>62.1</td>\n",
       "      <td>82.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>278</th>\n",
       "      <td>75.0</td>\n",
       "      <td>83.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>279</th>\n",
       "      <td>69.1</td>\n",
       "      <td>78.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>280</th>\n",
       "      <td>67.9</td>\n",
       "      <td>74.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>281</th>\n",
       "      <td>88.5</td>\n",
       "      <td>73.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>282</th>\n",
       "      <td>76.4</td>\n",
       "      <td>70.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>283</th>\n",
       "      <td>67.9</td>\n",
       "      <td>74.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>284</th>\n",
       "      <td>67.9</td>\n",
       "      <td>74.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>285</th>\n",
       "      <td>76.9</td>\n",
       "      <td>79.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>286</th>\n",
       "      <td>82.4</td>\n",
       "      <td>69.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>287</th>\n",
       "      <td>88.2</td>\n",
       "      <td>66.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>288</th>\n",
       "      <td>76.9</td>\n",
       "      <td>79.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>289</th>\n",
       "      <td>77.7</td>\n",
       "      <td>66.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>290</th>\n",
       "      <td>69.1</td>\n",
       "      <td>78.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>291</th>\n",
       "      <td>77.7</td>\n",
       "      <td>66.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>292</th>\n",
       "      <td>62.4</td>\n",
       "      <td>77.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>293</th>\n",
       "      <td>82.4</td>\n",
       "      <td>69.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>294</th>\n",
       "      <td>73.0</td>\n",
       "      <td>73.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>295</th>\n",
       "      <td>62.4</td>\n",
       "      <td>77.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>296</th>\n",
       "      <td>73.0</td>\n",
       "      <td>73.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>297</th>\n",
       "      <td>77.3</td>\n",
       "      <td>67.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>298</th>\n",
       "      <td>76.8</td>\n",
       "      <td>79.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>299</th>\n",
       "      <td>77.3</td>\n",
       "      <td>67.3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>300 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     Python  Java\n",
       "0      73.0  73.4\n",
       "1      85.9  56.1\n",
       "2      73.0  73.4\n",
       "3      88.5  73.4\n",
       "4      77.7  66.5\n",
       "5      76.9  79.6\n",
       "6      77.3  67.3\n",
       "7      82.4  69.6\n",
       "8      76.9  79.6\n",
       "9      67.9  74.8\n",
       "10     62.4  77.4\n",
       "11     85.9  56.1\n",
       "12     75.0  83.8\n",
       "13     62.4  77.4\n",
       "14     62.4  77.4\n",
       "15     62.4  77.4\n",
       "16     88.2  66.2\n",
       "17     77.0  79.1\n",
       "18     67.9  74.8\n",
       "19     85.9  56.1\n",
       "20     76.9  79.6\n",
       "21     67.9  74.8\n",
       "22     88.5  73.4\n",
       "23     82.4  69.6\n",
       "24     75.0  83.8\n",
       "25     75.0  83.8\n",
       "26     77.3  67.3\n",
       "27     85.9  56.1\n",
       "28     77.3  67.3\n",
       "29     67.9  74.8\n",
       "..      ...   ...\n",
       "270    77.0  79.1\n",
       "271    77.0  79.1\n",
       "272    88.5  73.4\n",
       "273    76.8  79.1\n",
       "274    76.9  79.6\n",
       "275    88.5  73.4\n",
       "276    88.5  73.4\n",
       "277    62.1  82.3\n",
       "278    75.0  83.8\n",
       "279    69.1  78.9\n",
       "280    67.9  74.8\n",
       "281    88.5  73.4\n",
       "282    76.4  70.4\n",
       "283    67.9  74.8\n",
       "284    67.9  74.8\n",
       "285    76.9  79.6\n",
       "286    82.4  69.6\n",
       "287    88.2  66.2\n",
       "288    76.9  79.6\n",
       "289    77.7  66.5\n",
       "290    69.1  78.9\n",
       "291    77.7  66.5\n",
       "292    62.4  77.4\n",
       "293    82.4  69.6\n",
       "294    73.0  73.4\n",
       "295    62.4  77.4\n",
       "296    73.0  73.4\n",
       "297    77.3  67.3\n",
       "298    76.8  79.1\n",
       "299    77.3  67.3\n",
       "\n",
       "[300 rows x 2 columns]"
      ]
     },
     "execution_count": 285,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#transform计算，返回的结果跟上面一样，但还是原来的长度\n",
    "def _mean(x):\n",
    "    return np.round(x.mean(),1)\n",
    "df.groupby(by = ['sex','class'])[['Python','Java']].transform(_mean)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "editorial-bahrain",
   "metadata": {},
   "source": [
    "### 分组聚合agg---可以计算多种方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 287,
   "id": "convenient-reach",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th colspan=\"3\" halign=\"left\">Python</th>\n",
       "      <th colspan=\"3\" halign=\"left\">Keras</th>\n",
       "      <th colspan=\"3\" halign=\"left\">Tensorflow</th>\n",
       "      <th colspan=\"3\" halign=\"left\">Java</th>\n",
       "      <th colspan=\"3\" halign=\"left\">C++</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>mean</th>\n",
       "      <th>amax</th>\n",
       "      <th>amin</th>\n",
       "      <th>mean</th>\n",
       "      <th>amax</th>\n",
       "      <th>amin</th>\n",
       "      <th>mean</th>\n",
       "      <th>amax</th>\n",
       "      <th>amin</th>\n",
       "      <th>mean</th>\n",
       "      <th>amax</th>\n",
       "      <th>amin</th>\n",
       "      <th>mean</th>\n",
       "      <th>amax</th>\n",
       "      <th>amin</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sex</th>\n",
       "      <th>class</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"8\" valign=\"top\">⼥</th>\n",
       "      <th>1</th>\n",
       "      <td>77.7</td>\n",
       "      <td>145</td>\n",
       "      <td>7</td>\n",
       "      <td>61.1</td>\n",
       "      <td>146</td>\n",
       "      <td>1</td>\n",
       "      <td>79.7</td>\n",
       "      <td>146</td>\n",
       "      <td>4</td>\n",
       "      <td>66.5</td>\n",
       "      <td>138</td>\n",
       "      <td>16</td>\n",
       "      <td>88.2</td>\n",
       "      <td>150</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>76.4</td>\n",
       "      <td>150</td>\n",
       "      <td>27</td>\n",
       "      <td>87.5</td>\n",
       "      <td>149</td>\n",
       "      <td>10</td>\n",
       "      <td>70.2</td>\n",
       "      <td>148</td>\n",
       "      <td>1</td>\n",
       "      <td>70.4</td>\n",
       "      <td>144</td>\n",
       "      <td>4</td>\n",
       "      <td>66.2</td>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>88.5</td>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "      <td>78.6</td>\n",
       "      <td>142</td>\n",
       "      <td>17</td>\n",
       "      <td>62.6</td>\n",
       "      <td>142</td>\n",
       "      <td>0</td>\n",
       "      <td>73.4</td>\n",
       "      <td>148</td>\n",
       "      <td>11</td>\n",
       "      <td>87.7</td>\n",
       "      <td>150</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>62.4</td>\n",
       "      <td>142</td>\n",
       "      <td>4</td>\n",
       "      <td>72.7</td>\n",
       "      <td>132</td>\n",
       "      <td>9</td>\n",
       "      <td>80.4</td>\n",
       "      <td>130</td>\n",
       "      <td>5</td>\n",
       "      <td>77.4</td>\n",
       "      <td>150</td>\n",
       "      <td>6</td>\n",
       "      <td>76.7</td>\n",
       "      <td>149</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>62.1</td>\n",
       "      <td>132</td>\n",
       "      <td>0</td>\n",
       "      <td>90.1</td>\n",
       "      <td>138</td>\n",
       "      <td>9</td>\n",
       "      <td>69.2</td>\n",
       "      <td>138</td>\n",
       "      <td>8</td>\n",
       "      <td>82.3</td>\n",
       "      <td>147</td>\n",
       "      <td>8</td>\n",
       "      <td>79.6</td>\n",
       "      <td>148</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>76.8</td>\n",
       "      <td>139</td>\n",
       "      <td>9</td>\n",
       "      <td>83.6</td>\n",
       "      <td>145</td>\n",
       "      <td>5</td>\n",
       "      <td>75.3</td>\n",
       "      <td>118</td>\n",
       "      <td>5</td>\n",
       "      <td>79.1</td>\n",
       "      <td>149</td>\n",
       "      <td>12</td>\n",
       "      <td>69.8</td>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>69.1</td>\n",
       "      <td>149</td>\n",
       "      <td>6</td>\n",
       "      <td>62.5</td>\n",
       "      <td>150</td>\n",
       "      <td>1</td>\n",
       "      <td>85.7</td>\n",
       "      <td>144</td>\n",
       "      <td>4</td>\n",
       "      <td>78.9</td>\n",
       "      <td>147</td>\n",
       "      <td>6</td>\n",
       "      <td>63.8</td>\n",
       "      <td>146</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>82.4</td>\n",
       "      <td>146</td>\n",
       "      <td>16</td>\n",
       "      <td>74.7</td>\n",
       "      <td>125</td>\n",
       "      <td>8</td>\n",
       "      <td>56.2</td>\n",
       "      <td>130</td>\n",
       "      <td>1</td>\n",
       "      <td>69.6</td>\n",
       "      <td>137</td>\n",
       "      <td>0</td>\n",
       "      <td>63.8</td>\n",
       "      <td>126</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"8\" valign=\"top\">男</th>\n",
       "      <th>1</th>\n",
       "      <td>73.0</td>\n",
       "      <td>149</td>\n",
       "      <td>8</td>\n",
       "      <td>79.0</td>\n",
       "      <td>150</td>\n",
       "      <td>16</td>\n",
       "      <td>66.0</td>\n",
       "      <td>148</td>\n",
       "      <td>7</td>\n",
       "      <td>73.4</td>\n",
       "      <td>149</td>\n",
       "      <td>3</td>\n",
       "      <td>86.7</td>\n",
       "      <td>149</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>77.0</td>\n",
       "      <td>141</td>\n",
       "      <td>18</td>\n",
       "      <td>88.0</td>\n",
       "      <td>141</td>\n",
       "      <td>7</td>\n",
       "      <td>84.1</td>\n",
       "      <td>145</td>\n",
       "      <td>21</td>\n",
       "      <td>79.1</td>\n",
       "      <td>145</td>\n",
       "      <td>2</td>\n",
       "      <td>105.6</td>\n",
       "      <td>149</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>67.9</td>\n",
       "      <td>149</td>\n",
       "      <td>8</td>\n",
       "      <td>63.9</td>\n",
       "      <td>123</td>\n",
       "      <td>5</td>\n",
       "      <td>85.6</td>\n",
       "      <td>145</td>\n",
       "      <td>29</td>\n",
       "      <td>74.8</td>\n",
       "      <td>147</td>\n",
       "      <td>7</td>\n",
       "      <td>69.4</td>\n",
       "      <td>124</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>88.2</td>\n",
       "      <td>149</td>\n",
       "      <td>10</td>\n",
       "      <td>73.4</td>\n",
       "      <td>145</td>\n",
       "      <td>2</td>\n",
       "      <td>71.2</td>\n",
       "      <td>136</td>\n",
       "      <td>5</td>\n",
       "      <td>66.2</td>\n",
       "      <td>125</td>\n",
       "      <td>9</td>\n",
       "      <td>80.6</td>\n",
       "      <td>143</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>75.0</td>\n",
       "      <td>137</td>\n",
       "      <td>2</td>\n",
       "      <td>63.9</td>\n",
       "      <td>146</td>\n",
       "      <td>1</td>\n",
       "      <td>72.7</td>\n",
       "      <td>146</td>\n",
       "      <td>2</td>\n",
       "      <td>83.8</td>\n",
       "      <td>148</td>\n",
       "      <td>1</td>\n",
       "      <td>72.0</td>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>77.3</td>\n",
       "      <td>149</td>\n",
       "      <td>14</td>\n",
       "      <td>82.9</td>\n",
       "      <td>145</td>\n",
       "      <td>9</td>\n",
       "      <td>69.4</td>\n",
       "      <td>124</td>\n",
       "      <td>6</td>\n",
       "      <td>67.3</td>\n",
       "      <td>150</td>\n",
       "      <td>4</td>\n",
       "      <td>59.5</td>\n",
       "      <td>144</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>85.9</td>\n",
       "      <td>150</td>\n",
       "      <td>2</td>\n",
       "      <td>88.1</td>\n",
       "      <td>150</td>\n",
       "      <td>12</td>\n",
       "      <td>62.3</td>\n",
       "      <td>149</td>\n",
       "      <td>25</td>\n",
       "      <td>56.1</td>\n",
       "      <td>136</td>\n",
       "      <td>5</td>\n",
       "      <td>81.2</td>\n",
       "      <td>146</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>76.9</td>\n",
       "      <td>136</td>\n",
       "      <td>25</td>\n",
       "      <td>66.6</td>\n",
       "      <td>130</td>\n",
       "      <td>5</td>\n",
       "      <td>65.7</td>\n",
       "      <td>137</td>\n",
       "      <td>4</td>\n",
       "      <td>79.6</td>\n",
       "      <td>149</td>\n",
       "      <td>12</td>\n",
       "      <td>82.4</td>\n",
       "      <td>137</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          Python           Keras           Tensorflow            Java       \\\n",
       "            mean amax amin  mean amax amin       mean amax amin  mean amax   \n",
       "sex class                                                                    \n",
       "⼥   1       77.7  145    7  61.1  146    1       79.7  146    4  66.5  138   \n",
       "    2       76.4  150   27  87.5  149   10       70.2  148    1  70.4  144   \n",
       "    3       88.5  150    0  78.6  142   17       62.6  142    0  73.4  148   \n",
       "    4       62.4  142    4  72.7  132    9       80.4  130    5  77.4  150   \n",
       "    5       62.1  132    0  90.1  138    9       69.2  138    8  82.3  147   \n",
       "    6       76.8  139    9  83.6  145    5       75.3  118    5  79.1  149   \n",
       "    7       69.1  149    6  62.5  150    1       85.7  144    4  78.9  147   \n",
       "    8       82.4  146   16  74.7  125    8       56.2  130    1  69.6  137   \n",
       "男   1       73.0  149    8  79.0  150   16       66.0  148    7  73.4  149   \n",
       "    2       77.0  141   18  88.0  141    7       84.1  145   21  79.1  145   \n",
       "    3       67.9  149    8  63.9  123    5       85.6  145   29  74.8  147   \n",
       "    4       88.2  149   10  73.4  145    2       71.2  136    5  66.2  125   \n",
       "    5       75.0  137    2  63.9  146    1       72.7  146    2  83.8  148   \n",
       "    6       77.3  149   14  82.9  145    9       69.4  124    6  67.3  150   \n",
       "    7       85.9  150    2  88.1  150   12       62.3  149   25  56.1  136   \n",
       "    8       76.9  136   25  66.6  130    5       65.7  137    4  79.6  149   \n",
       "\n",
       "                  C++            \n",
       "          amin   mean amax amin  \n",
       "sex class                        \n",
       "⼥   1       16   88.2  150   16  \n",
       "    2        4   66.2  150    0  \n",
       "    3       11   87.7  150   17  \n",
       "    4        6   76.7  149    4  \n",
       "    5        8   79.6  148    9  \n",
       "    6       12   69.8  150    0  \n",
       "    7        6   63.8  146    2  \n",
       "    8        0   63.8  126    0  \n",
       "男   1        3   86.7  149    7  \n",
       "    2        2  105.6  149    3  \n",
       "    3        7   69.4  124   22  \n",
       "    4        9   80.6  143    0  \n",
       "    5        1   72.0  150    0  \n",
       "    6        4   59.5  144    5  \n",
       "    7        5   81.2  146    1  \n",
       "    8       12   82.4  137    1  "
      ]
     },
     "execution_count": 287,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.groupby(by = ['sex','class']).agg([np.mean,np.max,np.min]).round(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 289,
   "id": "several-allah",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th colspan=\"3\" halign=\"left\">Python</th>\n",
       "      <th colspan=\"3\" halign=\"left\">Keras</th>\n",
       "      <th colspan=\"3\" halign=\"left\">Tensorflow</th>\n",
       "      <th colspan=\"3\" halign=\"left\">Java</th>\n",
       "      <th colspan=\"3\" halign=\"left\">C++</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>平均值</th>\n",
       "      <th>最大值</th>\n",
       "      <th>最小值</th>\n",
       "      <th>平均值</th>\n",
       "      <th>最大值</th>\n",
       "      <th>最小值</th>\n",
       "      <th>平均值</th>\n",
       "      <th>最大值</th>\n",
       "      <th>最小值</th>\n",
       "      <th>平均值</th>\n",
       "      <th>最大值</th>\n",
       "      <th>最小值</th>\n",
       "      <th>平均值</th>\n",
       "      <th>最大值</th>\n",
       "      <th>最小值</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sex</th>\n",
       "      <th>class</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"8\" valign=\"top\">⼥</th>\n",
       "      <th>1</th>\n",
       "      <td>77.7</td>\n",
       "      <td>145</td>\n",
       "      <td>7</td>\n",
       "      <td>61.1</td>\n",
       "      <td>146</td>\n",
       "      <td>1</td>\n",
       "      <td>79.7</td>\n",
       "      <td>146</td>\n",
       "      <td>4</td>\n",
       "      <td>66.5</td>\n",
       "      <td>138</td>\n",
       "      <td>16</td>\n",
       "      <td>88.2</td>\n",
       "      <td>150</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>76.4</td>\n",
       "      <td>150</td>\n",
       "      <td>27</td>\n",
       "      <td>87.5</td>\n",
       "      <td>149</td>\n",
       "      <td>10</td>\n",
       "      <td>70.2</td>\n",
       "      <td>148</td>\n",
       "      <td>1</td>\n",
       "      <td>70.4</td>\n",
       "      <td>144</td>\n",
       "      <td>4</td>\n",
       "      <td>66.2</td>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>88.5</td>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "      <td>78.6</td>\n",
       "      <td>142</td>\n",
       "      <td>17</td>\n",
       "      <td>62.6</td>\n",
       "      <td>142</td>\n",
       "      <td>0</td>\n",
       "      <td>73.4</td>\n",
       "      <td>148</td>\n",
       "      <td>11</td>\n",
       "      <td>87.7</td>\n",
       "      <td>150</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>62.4</td>\n",
       "      <td>142</td>\n",
       "      <td>4</td>\n",
       "      <td>72.7</td>\n",
       "      <td>132</td>\n",
       "      <td>9</td>\n",
       "      <td>80.4</td>\n",
       "      <td>130</td>\n",
       "      <td>5</td>\n",
       "      <td>77.4</td>\n",
       "      <td>150</td>\n",
       "      <td>6</td>\n",
       "      <td>76.7</td>\n",
       "      <td>149</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>62.1</td>\n",
       "      <td>132</td>\n",
       "      <td>0</td>\n",
       "      <td>90.1</td>\n",
       "      <td>138</td>\n",
       "      <td>9</td>\n",
       "      <td>69.2</td>\n",
       "      <td>138</td>\n",
       "      <td>8</td>\n",
       "      <td>82.3</td>\n",
       "      <td>147</td>\n",
       "      <td>8</td>\n",
       "      <td>79.6</td>\n",
       "      <td>148</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>76.8</td>\n",
       "      <td>139</td>\n",
       "      <td>9</td>\n",
       "      <td>83.6</td>\n",
       "      <td>145</td>\n",
       "      <td>5</td>\n",
       "      <td>75.3</td>\n",
       "      <td>118</td>\n",
       "      <td>5</td>\n",
       "      <td>79.1</td>\n",
       "      <td>149</td>\n",
       "      <td>12</td>\n",
       "      <td>69.8</td>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>69.1</td>\n",
       "      <td>149</td>\n",
       "      <td>6</td>\n",
       "      <td>62.5</td>\n",
       "      <td>150</td>\n",
       "      <td>1</td>\n",
       "      <td>85.7</td>\n",
       "      <td>144</td>\n",
       "      <td>4</td>\n",
       "      <td>78.9</td>\n",
       "      <td>147</td>\n",
       "      <td>6</td>\n",
       "      <td>63.8</td>\n",
       "      <td>146</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>82.4</td>\n",
       "      <td>146</td>\n",
       "      <td>16</td>\n",
       "      <td>74.7</td>\n",
       "      <td>125</td>\n",
       "      <td>8</td>\n",
       "      <td>56.2</td>\n",
       "      <td>130</td>\n",
       "      <td>1</td>\n",
       "      <td>69.6</td>\n",
       "      <td>137</td>\n",
       "      <td>0</td>\n",
       "      <td>63.8</td>\n",
       "      <td>126</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"8\" valign=\"top\">男</th>\n",
       "      <th>1</th>\n",
       "      <td>73.0</td>\n",
       "      <td>149</td>\n",
       "      <td>8</td>\n",
       "      <td>79.0</td>\n",
       "      <td>150</td>\n",
       "      <td>16</td>\n",
       "      <td>66.0</td>\n",
       "      <td>148</td>\n",
       "      <td>7</td>\n",
       "      <td>73.4</td>\n",
       "      <td>149</td>\n",
       "      <td>3</td>\n",
       "      <td>86.7</td>\n",
       "      <td>149</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>77.0</td>\n",
       "      <td>141</td>\n",
       "      <td>18</td>\n",
       "      <td>88.0</td>\n",
       "      <td>141</td>\n",
       "      <td>7</td>\n",
       "      <td>84.1</td>\n",
       "      <td>145</td>\n",
       "      <td>21</td>\n",
       "      <td>79.1</td>\n",
       "      <td>145</td>\n",
       "      <td>2</td>\n",
       "      <td>105.6</td>\n",
       "      <td>149</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>67.9</td>\n",
       "      <td>149</td>\n",
       "      <td>8</td>\n",
       "      <td>63.9</td>\n",
       "      <td>123</td>\n",
       "      <td>5</td>\n",
       "      <td>85.6</td>\n",
       "      <td>145</td>\n",
       "      <td>29</td>\n",
       "      <td>74.8</td>\n",
       "      <td>147</td>\n",
       "      <td>7</td>\n",
       "      <td>69.4</td>\n",
       "      <td>124</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>88.2</td>\n",
       "      <td>149</td>\n",
       "      <td>10</td>\n",
       "      <td>73.4</td>\n",
       "      <td>145</td>\n",
       "      <td>2</td>\n",
       "      <td>71.2</td>\n",
       "      <td>136</td>\n",
       "      <td>5</td>\n",
       "      <td>66.2</td>\n",
       "      <td>125</td>\n",
       "      <td>9</td>\n",
       "      <td>80.6</td>\n",
       "      <td>143</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>75.0</td>\n",
       "      <td>137</td>\n",
       "      <td>2</td>\n",
       "      <td>63.9</td>\n",
       "      <td>146</td>\n",
       "      <td>1</td>\n",
       "      <td>72.7</td>\n",
       "      <td>146</td>\n",
       "      <td>2</td>\n",
       "      <td>83.8</td>\n",
       "      <td>148</td>\n",
       "      <td>1</td>\n",
       "      <td>72.0</td>\n",
       "      <td>150</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>77.3</td>\n",
       "      <td>149</td>\n",
       "      <td>14</td>\n",
       "      <td>82.9</td>\n",
       "      <td>145</td>\n",
       "      <td>9</td>\n",
       "      <td>69.4</td>\n",
       "      <td>124</td>\n",
       "      <td>6</td>\n",
       "      <td>67.3</td>\n",
       "      <td>150</td>\n",
       "      <td>4</td>\n",
       "      <td>59.5</td>\n",
       "      <td>144</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>85.9</td>\n",
       "      <td>150</td>\n",
       "      <td>2</td>\n",
       "      <td>88.1</td>\n",
       "      <td>150</td>\n",
       "      <td>12</td>\n",
       "      <td>62.3</td>\n",
       "      <td>149</td>\n",
       "      <td>25</td>\n",
       "      <td>56.1</td>\n",
       "      <td>136</td>\n",
       "      <td>5</td>\n",
       "      <td>81.2</td>\n",
       "      <td>146</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>76.9</td>\n",
       "      <td>136</td>\n",
       "      <td>25</td>\n",
       "      <td>66.6</td>\n",
       "      <td>130</td>\n",
       "      <td>5</td>\n",
       "      <td>65.7</td>\n",
       "      <td>137</td>\n",
       "      <td>4</td>\n",
       "      <td>79.6</td>\n",
       "      <td>149</td>\n",
       "      <td>12</td>\n",
       "      <td>82.4</td>\n",
       "      <td>137</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          Python          Keras          Tensorflow           Java           \\\n",
       "             平均值  最大值 最小值   平均值  最大值 最小值        平均值  最大值 最小值   平均值  最大值 最小值   \n",
       "sex class                                                                     \n",
       "⼥   1       77.7  145   7  61.1  146   1       79.7  146   4  66.5  138  16   \n",
       "    2       76.4  150  27  87.5  149  10       70.2  148   1  70.4  144   4   \n",
       "    3       88.5  150   0  78.6  142  17       62.6  142   0  73.4  148  11   \n",
       "    4       62.4  142   4  72.7  132   9       80.4  130   5  77.4  150   6   \n",
       "    5       62.1  132   0  90.1  138   9       69.2  138   8  82.3  147   8   \n",
       "    6       76.8  139   9  83.6  145   5       75.3  118   5  79.1  149  12   \n",
       "    7       69.1  149   6  62.5  150   1       85.7  144   4  78.9  147   6   \n",
       "    8       82.4  146  16  74.7  125   8       56.2  130   1  69.6  137   0   \n",
       "男   1       73.0  149   8  79.0  150  16       66.0  148   7  73.4  149   3   \n",
       "    2       77.0  141  18  88.0  141   7       84.1  145  21  79.1  145   2   \n",
       "    3       67.9  149   8  63.9  123   5       85.6  145  29  74.8  147   7   \n",
       "    4       88.2  149  10  73.4  145   2       71.2  136   5  66.2  125   9   \n",
       "    5       75.0  137   2  63.9  146   1       72.7  146   2  83.8  148   1   \n",
       "    6       77.3  149  14  82.9  145   9       69.4  124   6  67.3  150   4   \n",
       "    7       85.9  150   2  88.1  150  12       62.3  149  25  56.1  136   5   \n",
       "    8       76.9  136  25  66.6  130   5       65.7  137   4  79.6  149  12   \n",
       "\n",
       "             C++           \n",
       "             平均值  最大值 最小值  \n",
       "sex class                  \n",
       "⼥   1       88.2  150  16  \n",
       "    2       66.2  150   0  \n",
       "    3       87.7  150  17  \n",
       "    4       76.7  149   4  \n",
       "    5       79.6  148   9  \n",
       "    6       69.8  150   0  \n",
       "    7       63.8  146   2  \n",
       "    8       63.8  126   0  \n",
       "男   1       86.7  149   7  \n",
       "    2      105.6  149   3  \n",
       "    3       69.4  124  22  \n",
       "    4       80.6  143   0  \n",
       "    5       72.0  150   0  \n",
       "    6       59.5  144   5  \n",
       "    7       81.2  146   1  \n",
       "    8       82.4  137   1  "
      ]
     },
     "execution_count": 289,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 计算的同时给计算列命名\n",
    "df.groupby(by = ['sex','class']).agg([('平均值',np.mean),('最大值',np.max),('最小值',np.min)]).round(1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 290,
   "id": "caroline-culture",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Python</th>\n",
       "      <th>Java</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sex</th>\n",
       "      <th>class</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"8\" valign=\"top\">⼥</th>\n",
       "      <th>1</th>\n",
       "      <td>145</td>\n",
       "      <td>16</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>150</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>150</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>142</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>132</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>139</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>149</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>146</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"8\" valign=\"top\">男</th>\n",
       "      <th>1</th>\n",
       "      <td>149</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>141</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>149</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>149</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>137</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>149</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>150</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>136</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           Python  Java\n",
       "sex class              \n",
       "⼥   1         145    16\n",
       "    2         150     4\n",
       "    3         150    11\n",
       "    4         142     6\n",
       "    5         132     8\n",
       "    6         139    12\n",
       "    7         149     6\n",
       "    8         146     0\n",
       "男   1         149     3\n",
       "    2         141     2\n",
       "    3         149     7\n",
       "    4         149     9\n",
       "    5         137     1\n",
       "    6         149     4\n",
       "    7         150     5\n",
       "    8         136    12"
      ]
     },
     "execution_count": 290,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#不同的列进行不同的计算---字典方式传入\n",
    "df.groupby(by = ['sex','class']).agg({'Python':np.max,'Java':np.min}).round(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "first-creek",
   "metadata": {},
   "source": [
    "### 透视表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 292,
   "id": "impressed-deployment",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>sex</th>\n",
       "      <th>class</th>\n",
       "      <th>Python</th>\n",
       "      <th>Keras</th>\n",
       "      <th>Tensorflow</th>\n",
       "      <th>Java</th>\n",
       "      <th>C++</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>男</td>\n",
       "      <td>1</td>\n",
       "      <td>114</td>\n",
       "      <td>150</td>\n",
       "      <td>87</td>\n",
       "      <td>3</td>\n",
       "      <td>149</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>男</td>\n",
       "      <td>7</td>\n",
       "      <td>134</td>\n",
       "      <td>150</td>\n",
       "      <td>36</td>\n",
       "      <td>8</td>\n",
       "      <td>57</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>男</td>\n",
       "      <td>1</td>\n",
       "      <td>123</td>\n",
       "      <td>87</td>\n",
       "      <td>117</td>\n",
       "      <td>50</td>\n",
       "      <td>87</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>⼥</td>\n",
       "      <td>3</td>\n",
       "      <td>77</td>\n",
       "      <td>84</td>\n",
       "      <td>75</td>\n",
       "      <td>15</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>⼥</td>\n",
       "      <td>1</td>\n",
       "      <td>19</td>\n",
       "      <td>1</td>\n",
       "      <td>56</td>\n",
       "      <td>16</td>\n",
       "      <td>109</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>男</td>\n",
       "      <td>8</td>\n",
       "      <td>59</td>\n",
       "      <td>101</td>\n",
       "      <td>126</td>\n",
       "      <td>149</td>\n",
       "      <td>78</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>男</td>\n",
       "      <td>6</td>\n",
       "      <td>43</td>\n",
       "      <td>88</td>\n",
       "      <td>107</td>\n",
       "      <td>79</td>\n",
       "      <td>45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>⼥</td>\n",
       "      <td>8</td>\n",
       "      <td>46</td>\n",
       "      <td>40</td>\n",
       "      <td>82</td>\n",
       "      <td>115</td>\n",
       "      <td>99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>男</td>\n",
       "      <td>8</td>\n",
       "      <td>103</td>\n",
       "      <td>7</td>\n",
       "      <td>81</td>\n",
       "      <td>79</td>\n",
       "      <td>105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>男</td>\n",
       "      <td>3</td>\n",
       "      <td>137</td>\n",
       "      <td>89</td>\n",
       "      <td>36</td>\n",
       "      <td>38</td>\n",
       "      <td>118</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>⼥</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>110</td>\n",
       "      <td>130</td>\n",
       "      <td>150</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>男</td>\n",
       "      <td>7</td>\n",
       "      <td>2</td>\n",
       "      <td>26</td>\n",
       "      <td>57</td>\n",
       "      <td>106</td>\n",
       "      <td>102</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>男</td>\n",
       "      <td>5</td>\n",
       "      <td>18</td>\n",
       "      <td>141</td>\n",
       "      <td>2</td>\n",
       "      <td>81</td>\n",
       "      <td>88</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>⼥</td>\n",
       "      <td>4</td>\n",
       "      <td>102</td>\n",
       "      <td>21</td>\n",
       "      <td>103</td>\n",
       "      <td>24</td>\n",
       "      <td>72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>⼥</td>\n",
       "      <td>4</td>\n",
       "      <td>48</td>\n",
       "      <td>94</td>\n",
       "      <td>22</td>\n",
       "      <td>61</td>\n",
       "      <td>147</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>⼥</td>\n",
       "      <td>4</td>\n",
       "      <td>23</td>\n",
       "      <td>97</td>\n",
       "      <td>58</td>\n",
       "      <td>82</td>\n",
       "      <td>139</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>男</td>\n",
       "      <td>4</td>\n",
       "      <td>21</td>\n",
       "      <td>116</td>\n",
       "      <td>17</td>\n",
       "      <td>114</td>\n",
       "      <td>84</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>男</td>\n",
       "      <td>2</td>\n",
       "      <td>62</td>\n",
       "      <td>135</td>\n",
       "      <td>108</td>\n",
       "      <td>123</td>\n",
       "      <td>134</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>男</td>\n",
       "      <td>3</td>\n",
       "      <td>8</td>\n",
       "      <td>90</td>\n",
       "      <td>110</td>\n",
       "      <td>7</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>男</td>\n",
       "      <td>7</td>\n",
       "      <td>145</td>\n",
       "      <td>145</td>\n",
       "      <td>106</td>\n",
       "      <td>42</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>男</td>\n",
       "      <td>8</td>\n",
       "      <td>114</td>\n",
       "      <td>54</td>\n",
       "      <td>11</td>\n",
       "      <td>17</td>\n",
       "      <td>55</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>男</td>\n",
       "      <td>3</td>\n",
       "      <td>110</td>\n",
       "      <td>47</td>\n",
       "      <td>142</td>\n",
       "      <td>143</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>⼥</td>\n",
       "      <td>3</td>\n",
       "      <td>47</td>\n",
       "      <td>119</td>\n",
       "      <td>76</td>\n",
       "      <td>93</td>\n",
       "      <td>91</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>⼥</td>\n",
       "      <td>8</td>\n",
       "      <td>88</td>\n",
       "      <td>31</td>\n",
       "      <td>68</td>\n",
       "      <td>132</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>男</td>\n",
       "      <td>5</td>\n",
       "      <td>99</td>\n",
       "      <td>95</td>\n",
       "      <td>82</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>男</td>\n",
       "      <td>5</td>\n",
       "      <td>108</td>\n",
       "      <td>119</td>\n",
       "      <td>77</td>\n",
       "      <td>105</td>\n",
       "      <td>115</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>男</td>\n",
       "      <td>6</td>\n",
       "      <td>14</td>\n",
       "      <td>92</td>\n",
       "      <td>57</td>\n",
       "      <td>71</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>男</td>\n",
       "      <td>7</td>\n",
       "      <td>129</td>\n",
       "      <td>54</td>\n",
       "      <td>25</td>\n",
       "      <td>80</td>\n",
       "      <td>11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>男</td>\n",
       "      <td>6</td>\n",
       "      <td>37</td>\n",
       "      <td>100</td>\n",
       "      <td>6</td>\n",
       "      <td>140</td>\n",
       "      <td>89</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>男</td>\n",
       "      <td>3</td>\n",
       "      <td>50</td>\n",
       "      <td>9</td>\n",
       "      <td>81</td>\n",
       "      <td>63</td>\n",
       "      <td>64</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>270</th>\n",
       "      <td>男</td>\n",
       "      <td>2</td>\n",
       "      <td>47</td>\n",
       "      <td>93</td>\n",
       "      <td>145</td>\n",
       "      <td>103</td>\n",
       "      <td>101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>271</th>\n",
       "      <td>男</td>\n",
       "      <td>2</td>\n",
       "      <td>95</td>\n",
       "      <td>118</td>\n",
       "      <td>21</td>\n",
       "      <td>133</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>272</th>\n",
       "      <td>⼥</td>\n",
       "      <td>3</td>\n",
       "      <td>100</td>\n",
       "      <td>53</td>\n",
       "      <td>71</td>\n",
       "      <td>93</td>\n",
       "      <td>119</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>273</th>\n",
       "      <td>⼥</td>\n",
       "      <td>6</td>\n",
       "      <td>39</td>\n",
       "      <td>27</td>\n",
       "      <td>115</td>\n",
       "      <td>46</td>\n",
       "      <td>133</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>274</th>\n",
       "      <td>男</td>\n",
       "      <td>8</td>\n",
       "      <td>128</td>\n",
       "      <td>109</td>\n",
       "      <td>46</td>\n",
       "      <td>12</td>\n",
       "      <td>124</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>275</th>\n",
       "      <td>⼥</td>\n",
       "      <td>3</td>\n",
       "      <td>130</td>\n",
       "      <td>78</td>\n",
       "      <td>116</td>\n",
       "      <td>34</td>\n",
       "      <td>109</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>276</th>\n",
       "      <td>⼥</td>\n",
       "      <td>3</td>\n",
       "      <td>133</td>\n",
       "      <td>98</td>\n",
       "      <td>58</td>\n",
       "      <td>121</td>\n",
       "      <td>25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>277</th>\n",
       "      <td>⼥</td>\n",
       "      <td>5</td>\n",
       "      <td>126</td>\n",
       "      <td>138</td>\n",
       "      <td>113</td>\n",
       "      <td>42</td>\n",
       "      <td>63</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>278</th>\n",
       "      <td>男</td>\n",
       "      <td>5</td>\n",
       "      <td>94</td>\n",
       "      <td>46</td>\n",
       "      <td>50</td>\n",
       "      <td>74</td>\n",
       "      <td>22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>279</th>\n",
       "      <td>⼥</td>\n",
       "      <td>7</td>\n",
       "      <td>23</td>\n",
       "      <td>1</td>\n",
       "      <td>125</td>\n",
       "      <td>67</td>\n",
       "      <td>130</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>280</th>\n",
       "      <td>男</td>\n",
       "      <td>3</td>\n",
       "      <td>45</td>\n",
       "      <td>15</td>\n",
       "      <td>70</td>\n",
       "      <td>103</td>\n",
       "      <td>26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>281</th>\n",
       "      <td>⼥</td>\n",
       "      <td>3</td>\n",
       "      <td>38</td>\n",
       "      <td>32</td>\n",
       "      <td>98</td>\n",
       "      <td>77</td>\n",
       "      <td>43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>282</th>\n",
       "      <td>⼥</td>\n",
       "      <td>2</td>\n",
       "      <td>144</td>\n",
       "      <td>111</td>\n",
       "      <td>9</td>\n",
       "      <td>115</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>283</th>\n",
       "      <td>男</td>\n",
       "      <td>3</td>\n",
       "      <td>70</td>\n",
       "      <td>123</td>\n",
       "      <td>36</td>\n",
       "      <td>58</td>\n",
       "      <td>59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>284</th>\n",
       "      <td>男</td>\n",
       "      <td>3</td>\n",
       "      <td>33</td>\n",
       "      <td>27</td>\n",
       "      <td>93</td>\n",
       "      <td>95</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>285</th>\n",
       "      <td>男</td>\n",
       "      <td>8</td>\n",
       "      <td>121</td>\n",
       "      <td>24</td>\n",
       "      <td>112</td>\n",
       "      <td>113</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>286</th>\n",
       "      <td>⼥</td>\n",
       "      <td>8</td>\n",
       "      <td>134</td>\n",
       "      <td>88</td>\n",
       "      <td>117</td>\n",
       "      <td>90</td>\n",
       "      <td>32</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>287</th>\n",
       "      <td>男</td>\n",
       "      <td>4</td>\n",
       "      <td>34</td>\n",
       "      <td>49</td>\n",
       "      <td>42</td>\n",
       "      <td>34</td>\n",
       "      <td>142</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>288</th>\n",
       "      <td>男</td>\n",
       "      <td>8</td>\n",
       "      <td>59</td>\n",
       "      <td>118</td>\n",
       "      <td>63</td>\n",
       "      <td>92</td>\n",
       "      <td>114</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>289</th>\n",
       "      <td>⼥</td>\n",
       "      <td>1</td>\n",
       "      <td>122</td>\n",
       "      <td>42</td>\n",
       "      <td>16</td>\n",
       "      <td>108</td>\n",
       "      <td>105</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>290</th>\n",
       "      <td>⼥</td>\n",
       "      <td>7</td>\n",
       "      <td>6</td>\n",
       "      <td>22</td>\n",
       "      <td>79</td>\n",
       "      <td>96</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>291</th>\n",
       "      <td>⼥</td>\n",
       "      <td>1</td>\n",
       "      <td>114</td>\n",
       "      <td>12</td>\n",
       "      <td>63</td>\n",
       "      <td>63</td>\n",
       "      <td>79</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>292</th>\n",
       "      <td>⼥</td>\n",
       "      <td>4</td>\n",
       "      <td>112</td>\n",
       "      <td>66</td>\n",
       "      <td>62</td>\n",
       "      <td>30</td>\n",
       "      <td>131</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>293</th>\n",
       "      <td>⼥</td>\n",
       "      <td>8</td>\n",
       "      <td>138</td>\n",
       "      <td>59</td>\n",
       "      <td>51</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>294</th>\n",
       "      <td>男</td>\n",
       "      <td>1</td>\n",
       "      <td>149</td>\n",
       "      <td>147</td>\n",
       "      <td>38</td>\n",
       "      <td>57</td>\n",
       "      <td>121</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>295</th>\n",
       "      <td>⼥</td>\n",
       "      <td>4</td>\n",
       "      <td>142</td>\n",
       "      <td>52</td>\n",
       "      <td>120</td>\n",
       "      <td>59</td>\n",
       "      <td>149</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>296</th>\n",
       "      <td>男</td>\n",
       "      <td>1</td>\n",
       "      <td>85</td>\n",
       "      <td>104</td>\n",
       "      <td>11</td>\n",
       "      <td>91</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>297</th>\n",
       "      <td>男</td>\n",
       "      <td>6</td>\n",
       "      <td>86</td>\n",
       "      <td>74</td>\n",
       "      <td>83</td>\n",
       "      <td>137</td>\n",
       "      <td>101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>298</th>\n",
       "      <td>⼥</td>\n",
       "      <td>6</td>\n",
       "      <td>139</td>\n",
       "      <td>27</td>\n",
       "      <td>56</td>\n",
       "      <td>144</td>\n",
       "      <td>117</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>299</th>\n",
       "      <td>男</td>\n",
       "      <td>6</td>\n",
       "      <td>81</td>\n",
       "      <td>141</td>\n",
       "      <td>124</td>\n",
       "      <td>54</td>\n",
       "      <td>86</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>300 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    sex  class  Python  Keras  Tensorflow  Java  C++\n",
       "0     男      1     114    150          87     3  149\n",
       "1     男      7     134    150          36     8   57\n",
       "2     男      1     123     87         117    50   87\n",
       "3     ⼥      3      77     84          75    15   55\n",
       "4     ⼥      1      19      1          56    16  109\n",
       "5     男      8      59    101         126   149   78\n",
       "6     男      6      43     88         107    79   45\n",
       "7     ⼥      8      46     40          82   115   99\n",
       "8     男      8     103      7          81    79  105\n",
       "9     男      3     137     89          36    38  118\n",
       "10    ⼥      4       4    110         130   150   46\n",
       "11    男      7       2     26          57   106  102\n",
       "12    男      5      18    141           2    81   88\n",
       "13    ⼥      4     102     21         103    24   72\n",
       "14    ⼥      4      48     94          22    61  147\n",
       "15    ⼥      4      23     97          58    82  139\n",
       "16    男      4      21    116          17   114   84\n",
       "17    男      2      62    135         108   123  134\n",
       "18    男      3       8     90         110     7   89\n",
       "19    男      7     145    145         106    42   80\n",
       "20    男      8     114     54          11    17   55\n",
       "21    男      3     110     47         142   143   22\n",
       "22    ⼥      3      47    119          76    93   91\n",
       "23    ⼥      8      88     31          68   132   22\n",
       "24    男      5      99     95          82     1    0\n",
       "25    男      5     108    119          77   105  115\n",
       "26    男      6      14     92          57    71   17\n",
       "27    男      7     129     54          25    80   11\n",
       "28    男      6      37    100           6   140   89\n",
       "29    男      3      50      9          81    63   64\n",
       "..   ..    ...     ...    ...         ...   ...  ...\n",
       "270   男      2      47     93         145   103  101\n",
       "271   男      2      95    118          21   133   42\n",
       "272   ⼥      3     100     53          71    93  119\n",
       "273   ⼥      6      39     27         115    46  133\n",
       "274   男      8     128    109          46    12  124\n",
       "275   ⼥      3     130     78         116    34  109\n",
       "276   ⼥      3     133     98          58   121   25\n",
       "277   ⼥      5     126    138         113    42   63\n",
       "278   男      5      94     46          50    74   22\n",
       "279   ⼥      7      23      1         125    67  130\n",
       "280   男      3      45     15          70   103   26\n",
       "281   ⼥      3      38     32          98    77   43\n",
       "282   ⼥      2     144    111           9   115   14\n",
       "283   男      3      70    123          36    58   59\n",
       "284   男      3      33     27          93    95   76\n",
       "285   男      8     121     24         112   113   42\n",
       "286   ⼥      8     134     88         117    90   32\n",
       "287   男      4      34     49          42    34  142\n",
       "288   男      8      59    118          63    92  114\n",
       "289   ⼥      1     122     42          16   108  105\n",
       "290   ⼥      7       6     22          79    96   23\n",
       "291   ⼥      1     114     12          63    63   79\n",
       "292   ⼥      4     112     66          62    30  131\n",
       "293   ⼥      8     138     59          51     6    0\n",
       "294   男      1     149    147          38    57  121\n",
       "295   ⼥      4     142     52         120    59  149\n",
       "296   男      1      85    104          11    91    7\n",
       "297   男      6      86     74          83   137  101\n",
       "298   ⼥      6     139     27          56   144  117\n",
       "299   男      6      81    141         124    54   86\n",
       "\n",
       "[300 rows x 7 columns]"
      ]
     },
     "execution_count": 292,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 296,
   "id": "finite-watch",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Java</th>\n",
       "      <th>Python</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sex</th>\n",
       "      <th>class</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"8\" valign=\"top\">⼥</th>\n",
       "      <th>1</th>\n",
       "      <td>66.5</td>\n",
       "      <td>77.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>70.4</td>\n",
       "      <td>76.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>73.4</td>\n",
       "      <td>88.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>77.4</td>\n",
       "      <td>62.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>82.3</td>\n",
       "      <td>62.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>79.1</td>\n",
       "      <td>76.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>78.9</td>\n",
       "      <td>69.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>69.6</td>\n",
       "      <td>82.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"8\" valign=\"top\">男</th>\n",
       "      <th>1</th>\n",
       "      <td>73.4</td>\n",
       "      <td>73.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>79.1</td>\n",
       "      <td>77.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>74.8</td>\n",
       "      <td>67.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>66.2</td>\n",
       "      <td>88.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>83.8</td>\n",
       "      <td>75.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>67.3</td>\n",
       "      <td>77.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>56.1</td>\n",
       "      <td>85.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>79.6</td>\n",
       "      <td>76.9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           Java  Python\n",
       "sex class              \n",
       "⼥   1      66.5    77.7\n",
       "    2      70.4    76.4\n",
       "    3      73.4    88.5\n",
       "    4      77.4    62.4\n",
       "    5      82.3    62.1\n",
       "    6      79.1    76.8\n",
       "    7      78.9    69.1\n",
       "    8      69.6    82.4\n",
       "男   1      73.4    73.0\n",
       "    2      79.1    77.0\n",
       "    3      74.8    67.9\n",
       "    4      66.2    88.2\n",
       "    5      83.8    75.0\n",
       "    6      67.3    77.3\n",
       "    7      56.1    85.9\n",
       "    8      79.6    76.9"
      ]
     },
     "execution_count": 296,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.pivot_table(values=['Python','Java'],index=['sex','class'],aggfunc='mean').round(1)\n",
    "#此结果与之前的分组聚合结果一样"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 297,
   "id": "sweet-personal",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th colspan=\"2\" halign=\"left\">Java</th>\n",
       "      <th>Python</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>平均值</th>\n",
       "      <th>最大值</th>\n",
       "      <th>平均值</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sex</th>\n",
       "      <th>class</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"8\" valign=\"top\">⼥</th>\n",
       "      <th>1</th>\n",
       "      <td>66.5</td>\n",
       "      <td>138.0</td>\n",
       "      <td>77.7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>70.4</td>\n",
       "      <td>144.0</td>\n",
       "      <td>76.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>73.4</td>\n",
       "      <td>148.0</td>\n",
       "      <td>88.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>77.4</td>\n",
       "      <td>150.0</td>\n",
       "      <td>62.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>82.3</td>\n",
       "      <td>147.0</td>\n",
       "      <td>62.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>79.1</td>\n",
       "      <td>149.0</td>\n",
       "      <td>76.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>78.9</td>\n",
       "      <td>147.0</td>\n",
       "      <td>69.1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>69.6</td>\n",
       "      <td>137.0</td>\n",
       "      <td>82.4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"8\" valign=\"top\">男</th>\n",
       "      <th>1</th>\n",
       "      <td>73.4</td>\n",
       "      <td>149.0</td>\n",
       "      <td>73.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>79.1</td>\n",
       "      <td>145.0</td>\n",
       "      <td>77.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>74.8</td>\n",
       "      <td>147.0</td>\n",
       "      <td>67.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>66.2</td>\n",
       "      <td>125.0</td>\n",
       "      <td>88.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>83.8</td>\n",
       "      <td>148.0</td>\n",
       "      <td>75.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>67.3</td>\n",
       "      <td>150.0</td>\n",
       "      <td>77.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>56.1</td>\n",
       "      <td>136.0</td>\n",
       "      <td>85.9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>79.6</td>\n",
       "      <td>149.0</td>\n",
       "      <td>76.9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           Java        Python\n",
       "            平均值    最大值    平均值\n",
       "sex class                    \n",
       "⼥   1      66.5  138.0   77.7\n",
       "    2      70.4  144.0   76.4\n",
       "    3      73.4  148.0   88.5\n",
       "    4      77.4  150.0   62.4\n",
       "    5      82.3  147.0   62.1\n",
       "    6      79.1  149.0   76.8\n",
       "    7      78.9  147.0   69.1\n",
       "    8      69.6  137.0   82.4\n",
       "男   1      73.4  149.0   73.0\n",
       "    2      79.1  145.0   77.0\n",
       "    3      74.8  147.0   67.9\n",
       "    4      66.2  125.0   88.2\n",
       "    5      83.8  148.0   75.0\n",
       "    6      67.3  150.0   77.3\n",
       "    7      56.1  136.0   85.9\n",
       "    8      79.6  149.0   76.9"
      ]
     },
     "execution_count": 297,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.pivot_table(values=['Python','Java'],\n",
    "               index=['sex','class'],\n",
    "               aggfunc={'Python':[('平均值',np.mean)],'Java':[('平均值',np.mean),('最大值',np.max)]}\n",
    "              ).round(1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "external-irrigation",
   "metadata": {},
   "source": [
    "## 时间序列"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "developed-mauritius",
   "metadata": {},
   "source": [
    "### 时间戳"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 302,
   "id": "peripheral-cloud",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timestamp('2020-09-15 20:00:00')"
      ]
     },
     "execution_count": 302,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.Timestamp('2020.09.15 20')  #时刻数据，表示一个时间点"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 303,
   "id": "determined-psychology",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Period('2020-08', 'M')"
      ]
     },
     "execution_count": 303,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.Period('2020-8-24',freq = 'M') # 时期数据，表示一段时间，也表示频率"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eligible-christianity",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "351px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
